From patchwork Fri Jun 24 16:45:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 12894872 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 BB064CCA47E for ; Fri, 24 Jun 2022 16:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbiFXQqK (ORCPT ); Fri, 24 Jun 2022 12:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbiFXQp7 (ORCPT ); Fri, 24 Jun 2022 12:45:59 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4138B50032; Fri, 24 Jun 2022 09:45:58 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25OFYD4L023009; Fri, 24 Jun 2022 16:45:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=0H2EswXejg6sqJQb4PJ8L6Nk0KnaVB7h/56TX6J++lU=; b=VdjyxT5kqifUhaS8MEQIZ3ejZxOSnKhja353oCwqF2yEnV8k52MvF80AA30Dj22DfFnP s3kY8SDZwnUQJ33ChY6Div4GGDn7O1LWSfbp6PLnV6XHO/mTsi4AF3fVeNyiT9JZd/w8 wTZLEDsHqjWyFH74NxpQMSp1NbMqA8/GFCpRwahRHaDcxxEShlkDV1JuYop7zyJoJ09n wTPANmDEfvJeB6hqXE+2Z3+AFjWi3GWGSbl8Pn9ngyoCAE6lfCohMndqI7jdQMJgERIl cjK7z/PGsdQR+wjClupldNySB8Xre/w9GuYL34SwUdFRgOb0lDKM+Ygp3RW+mlyRMfbe nQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gs5a0pbx6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jun 2022 16:45:30 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25OGUf5V034023; Fri, 24 Jun 2022 16:45:28 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gtd9xc0t1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jun 2022 16:45:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MuciVzvmypkKQwqjyV2cuiQMPHtuCjNKcO6mR85gObpnc0k8T+8Di3UqO5hlBvU4dyLBkjmSxSIKRm+ay2FvQMYad3WYPAFrUkc4AIIvc9eNX6Gg3yLIyVyQIMzoqiqwl45aTVQLpwlMjTDG7+mtIPauZW0Ob2zuLAlpQJFK+6pLWNALkW0FA2OxVyl0ooQaYEL6//pnEtdC7OXdalHckzRq6DZEkVIF6nBcG4nUVNrzQeC7Apy69+GZcOoAlypia5GN7jJuqGgADhMlkwiZVhMmupjL8IOQn95khUGyciqKoKiOTX4VqUI9tdkFAE6NMuo8go29/nJ6SOF3JNt94A== 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=0H2EswXejg6sqJQb4PJ8L6Nk0KnaVB7h/56TX6J++lU=; b=LrX422UTCjYOhGu7Iu17TiU42TUMk1X0j+mqudtbuyaMb4WVtZ/fPAhjH1fFt6QgiuwjiX55bf4it+fo75oha4RimhGjjMq3RC1mVycQdQShrEgADrxeKTTlB2+yfmiQTdFcpr/tFTbquOouBcxbYLSQGAquMvLMbvkVgsQeYuydHZ6KLEgogmh0BHT30obOXrf19GcwiLFbh1XpjvbOX+u5OhgmlvRwCJg0g2MIXhQCGSBVbCmlw3JOk8PVJXi+lq3mwq+ojlfV0sKwYXMCXUzucSTqhhUVcybFo39e1F41o+G1e/C1usVqxLRuHZuaDcCdAJA7VUZYgeaYHWGB8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0H2EswXejg6sqJQb4PJ8L6Nk0KnaVB7h/56TX6J++lU=; b=JKIdxdIzZEugHuiYKMx3rlTYajq5GhedNhLZrOKPjsvX7h4tpoKvFIdOlo59l4ntbwGI8Bpq74HX+24+sTHulMFMFOQLRxLk4NFhk+PCAvdG06qqse00NXwgpaV3rilxdKfr9Kq3rOWeen5JwmXPMX2ZYO/vNatCh5bjOdROGJk= Received: from BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) by CH0PR10MB5115.namprd10.prod.outlook.com (2603:10b6:610:c4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Fri, 24 Jun 2022 16:45:27 +0000 Received: from BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::a080:c357:962c:eb5]) by BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::a080:c357:962c:eb5%5]) with mapi id 15.20.5373.017; Fri, 24 Jun 2022 16:45:27 +0000 From: Alan Maguire To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, jolsa@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, mhiramat@kernel.org, akpm@linux-foundation.org, void@manifault.com, swboyd@chromium.org, ndesaulniers@google.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Alan Maguire Subject: [RFC bpf-next 1/2] bpf: add a kallsyms BPF iterator Date: Fri, 24 Jun 2022 17:45:17 +0100 Message-Id: <1656089118-577-2-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1656089118-577-1-git-send-email-alan.maguire@oracle.com> References: <1656089118-577-1-git-send-email-alan.maguire@oracle.com> X-ClientProxiedBy: LO4P123CA0396.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::23) To BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8680f5c7-5ef9-413a-cb96-08da5600f10b X-MS-TrafficTypeDiagnostic: CH0PR10MB5115:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zLLDK1MD/7MzieVo7mkJizNZ0LZNxYTpe4O0kjnXd3gVCK6cv2o9zAW6tleXGuIhVRiZh9vdRhKBlHVeTSLA2MfOCOl/xDB4JisoeHFO2UEE1ajslmPcYRZtuu2H54MtyQNnDqbXHX5KrkoFH1n2H8PhPFfqsRApGsxXF9xfDCmBPPYNmG9dl/H6NUWtPrhd6uJVqC31b3tHZZtNPxgQSjfjqWDdu0ccCunA8oibT1B4mN+/FyIONPQgbB9lkekRasa72DhvOCwjNZ9bJKdMz+rFF7K8w7R+4Z+x9rvClauVms4oqw7pjrlFud7949iF7Z0qoObsuUvrFhAELEpdxB715fFLQMP9pbnwqjmqr8b50qsrjGng++2UDOgpM/HK9VDexthQn+nj0NNO+fKhgfIGHuV3uSZ9QcV6QEjbyQNKM41Mx42hU5tBtF4XnChO1PROgBKWO/wszlKUzNZgAC8o16Rk9tDl/wnuhxU91Tm4ux01l6WiV0AfqjZ4Qw7qKnLh3BCr50WnROCAEzLLex1niudkE6Ph0rOg6XGS5Zg8yJYVckJXiTePg6o4Q38vtT5ohUhFbxSk12uv+B1idCk9RDl6XcCvEK7eQj1pTI9CtKxi0FxiIwOgA6j0BDLfbiesj1w7eBfmdFlrSv7kEAw3AatELSXuhPsMriW+WUX+JKegPFL9cNawT6aoZrq19LjQNqbFWwbu/NatLyECaSSnnl75Guz3XXH8sHZVkLzDl27V/hG7R8dd7VEJUPyifxNVqXVe33xmP1Wfxnmh7C7UvA2h+BYYy9E7JFqd5Z3koMD4XAFSTmTmMGuCdLq+ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB5267.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(39860400002)(366004)(396003)(376002)(346002)(136003)(4326008)(8676002)(186003)(83380400001)(44832011)(478600001)(66476007)(5660300002)(2906002)(66556008)(38100700002)(7416002)(66946007)(8936002)(6506007)(107886003)(52116002)(2616005)(41300700001)(6512007)(26005)(6666004)(966005)(316002)(36756003)(38350700002)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 27kQTbdONJA7tALuCVPckhYOlMF8S0UTjX9u3+qQ1OU9ppmUxhcOJyAETuAGa7bJDipPJdA4e8QMyE4dUpyW7oqKC+W1nilpGuA0sYUQCsPtbpz0GsGSwNvdGW95ERUi7j9y0jgqyzLoIdltBFMhef4q0P2stkQgy4lVECmyj/PnrGOZti8xMye5g0xWDbl0G63/SBk9xTV95ATPh6nyKdK1F6BqDwHZ/82IpivDeXsm91EgpAsEHkOvo5lFT+GAIhJcgdVKYyIJjiHjPxDB583shD+lddFywe5KeFMho1yhItBurCSocgtw5m4449tH79lnmFM/DhTPUaxSyrkIMhN7yczT16V+TnMpsdgqbbS8yOMqhfblULis4p2lUdIPUb0uNjR7RhUxTBEZdN0kcy/KCsOJfIoJ/7L0mdZagrxi2bJ9cFyEUEr9g8Td3WQuN9qRF/R2BE7LopbgrJtLRIoAeia7Pc+YP0Li5W1/PkMRYw6iHt8QOFZm7XOg2ZLSYc3a8WWCZy3gU+yY0qShBlkSbqsCtvdv9bVMTIsH797iCh7qidFqLHLklEI0oe1DOhKwBd0gXFqCgA93YkJAFR3MP3b4ohPRa08tq4R+wmgX/VS6k+tktNbwXqrq8ZDhwSW5O2XeVlsfNkyG2WtYc+An/0ZzymqNwHvwknB+ee80KBY8MbKz9o4sIQox92pgeDWgGzrmGRsjBTIKwC25WPhGfPd7P3WeMovX7A8Ht9mMOuYDMg41QIG8u6/V/50raBllYCk1gpJVlE51c1UkH30iyRhJ/GeFa8fpAptunPhbrMxTaNZ9B978DEkl2ZNBwngqisLRUHmXEzFHykyIADWsq+Dbb65S2YisERDKtihOijP54s7s12720fMJ7eYYSNBpg6wQyF+W0xw+qZI3aw32rV+x14FutRDJx2lzseJI74qXx1fKb4GZXu//qIeIkXfbVtcI6+oS258U3uDON58k24vHkrmY1+GCWSevp6FYAB/mtEk6fLIPaCG8TtiSLS4Ds7Mv+ZKtTNX9k761l9MWohNw/Ajs0AEmLMmI7ilzLw4jcWusruy6NzK4qza/RgtmLuVPlzbiNOZdz4FL0wEw1nZ0yLsFZiBLF+nrvZK6jG4F2rgMnoMKhZWL5TcMNdDGzNgfOV/UWnBENduQ0hkDmLMoYNheOBEMlxtSNmC/hh+pNk60CKsSYp/JlUAoa7mmtnwdQ0BK+xLCpRIuqq7hOcN23OH4pOGxBcxjoYxXmKjsihM+5/YaACTm/nBdwyCdgZxbXzSXjduREA5WNeAEsz6KFzqguUbmr43KJFPPpRnqqpapJjp+ASh6n/w+69Aql8GA3Tp6P+mTBELquS7ODPZQc+cbdOwZ2qeCM2vbxkDvrR0WhUUJEtbRIE4zLG/WrTG0TtC0Y99eo86pJPSG9BTsLjEhFgh6H4W3b3+hWLGkxgWWbCPcpstg3A9k3iRZB+Hx5ImBF0ajJfKQCzNxr458KUJ88kni+0ncSEEl/5CGn4NZUJeyD3dfRJq6rDBbVR/EurIh7DCudO1II8/Sg45ZL9owI+tO1GmxVUiKhYdDFmLANuCsEIv5NL7T X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8680f5c7-5ef9-413a-cb96-08da5600f10b X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5267.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2022 16:45:27.2448 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cA9HxmkkKdU/ddLXvL4T5ef4gMTzRKz6PACK9yqw/xAeE2eh3KaHNCJyUhsqO3tfKriRiPdkMg8x1K1SWnbVsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5115 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-24_08:2022-06-23,2022-06-24 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206240064 X-Proofpoint-ORIG-GUID: bRfEBvaPNkMv5tAnxtyNGs2tLHOf5Ivw X-Proofpoint-GUID: bRfEBvaPNkMv5tAnxtyNGs2tLHOf5Ivw Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC add a "kallsyms" iterator which provides access to a "struct kallsym_iter" for each symbol. Intent is to support more flexible symbol parsing as discussed in [1]. [1] https://lore.kernel.org/all/YjRPZj6Z8vuLeEZo@krava/ Suggested-by: Alexei Starovoitov Signed-off-by: Alan Maguire --- kernel/kallsyms.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index fbdf8d3..ffaf464 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -30,6 +30,7 @@ #include #include #include +#include /* * These will be re-linked against their real values @@ -799,6 +800,95 @@ static int s_show(struct seq_file *m, void *p) .show = s_show }; +#ifdef CONFIG_BPF_SYSCALL + +struct bpf_iter__kallsyms { + __bpf_md_ptr(struct bpf_iter_meta *, meta); + __bpf_md_ptr(struct kallsym_iter *, kallsym_iter); +}; + +static int s_prog_seq_show(struct seq_file *m, bool in_stop) +{ + struct bpf_iter__kallsyms ctx; + struct bpf_iter_meta meta; + struct bpf_prog *prog; + + meta.seq = m; + prog = bpf_iter_get_info(&meta, in_stop); + if (!prog) + return 0; + + ctx.meta = &meta; + ctx.kallsym_iter = m ? m->private : NULL; + return bpf_iter_run_prog(prog, &ctx); +} + +static int bpf_iter_s_seq_show(struct seq_file *m, void *p) +{ + return s_prog_seq_show(m, false); +} + +static void bpf_iter_s_seq_stop(struct seq_file *m, void *p) +{ + if (!p) + (void) s_prog_seq_show(m, true); + else + s_stop(m, p); +} + +static const struct seq_operations bpf_iter_kallsyms_ops = { + .start = s_start, + .next = s_next, + .stop = bpf_iter_s_seq_stop, + .show = bpf_iter_s_seq_show, +}; + +#if defined(CONFIG_PROC_FS) + +static int bpf_iter_s_init(void *priv_data, struct bpf_iter_aux_info *aux) +{ + struct kallsym_iter *iter = priv_data; + + reset_iter(iter, 0); + + iter->show_value = true; + + return 0; +} + +DEFINE_BPF_ITER_FUNC(kallsyms, struct bpf_iter_meta *meta, struct kallsym_iter *kallsym_iter) + +static const struct bpf_iter_seq_info kallsyms_iter_seq_info = { + .seq_ops = &bpf_iter_kallsyms_ops, + .init_seq_private = bpf_iter_s_init, + .fini_seq_private = NULL, + .seq_priv_size = sizeof(struct kallsym_iter), +}; + +static struct bpf_iter_reg kallsyms_iter_reg_info = { + .target = "kallsyms", + .ctx_arg_info_size = 1, + .ctx_arg_info = { + { offsetof(struct bpf_iter__kallsyms, kallsym_iter), + PTR_TO_BTF_ID_OR_NULL }, + }, + .seq_info = &kallsyms_iter_seq_info, +}; + +BTF_ID_LIST(btf_kallsym_iter_id) +BTF_ID(struct, kallsym_iter) + +static void __init bpf_kallsyms_iter_register(void) +{ + kallsyms_iter_reg_info.ctx_arg_info[0].btf_id = *btf_kallsym_iter_id; + if (bpf_iter_reg_target(&kallsyms_iter_reg_info)) + pr_warn("Warning: could not register bpf kallsyms iterator\n"); +} + +#endif /* CONFIG_PROC_FS */ + +#endif /* CONFIG_BPF_SYSCALL */ + static inline int kallsyms_for_perf(void) { #ifdef CONFIG_PERF_EVENTS @@ -885,6 +975,9 @@ const char *kdb_walk_kallsyms(loff_t *pos) static int __init kallsyms_init(void) { proc_create("kallsyms", 0444, NULL, &kallsyms_proc_ops); +#if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_PROC_FS) + bpf_kallsyms_iter_register(); +#endif return 0; } device_initcall(kallsyms_init); From patchwork Fri Jun 24 16:45:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 12894871 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 68AD2C433EF for ; Fri, 24 Jun 2022 16:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229994AbiFXQqI (ORCPT ); Fri, 24 Jun 2022 12:46:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbiFXQp6 (ORCPT ); Fri, 24 Jun 2022 12:45:58 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B2E34DF67; Fri, 24 Jun 2022 09:45:57 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25OFYI2w004195; Fri, 24 Jun 2022 16:45:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=3HCiqpwJy3Y0NvcXu4dw+pH81U/5AfQMqOEVw9MtyWI=; b=Mzuy2GB0GLqQ1OovTI6pvd4OIYAYk3bbJSqacttZCMEW1IbJ8uOZ2cT/cZMZXuh0vJH0 gG7efDQKcZUALXrwXvsBRI4G0a0qeaYvs2Tgcnspt5aNb5dan2NkP1KO+ETntBqgTuoe nqocH5gu8aZ6jHQJ3i9Bc+BwTM8rCdQBy20FdgvpEMjFKUB08ZBkqo1uCTDekgmhf+UR U3dV9CLARoLxgK2eBslnUqAfYOX0pqGPXVaMawPSSlhfwwaz8r6AIPrl1LPqAq2wZ/B0 3qP8y4KBZRlbUMtveg+CKJV/RIxjZJcOT1rxLYzH0J3A0yY+D3hR6B5segpr03+GqWgx UA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gs78u6add-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jun 2022 16:45:32 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25OGV6Yn023811; Fri, 24 Jun 2022 16:45:32 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gtf5frqfa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jun 2022 16:45:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VeNfLSdGGe9FI8ZOOvwN8WTV3e5Af1G9P2Ds9QQO81NRr0GgzE8qxKCEQ+bMo7iHNI9cFlmqCcFn5pJBfXqKen3v1XKlsTEWlBc1VGFNqorJBFzXaIk4sw8FrKJnw5u/omenZDI++oAZH9p3MWYxDDIFptTbcu4pGRz4FY4855w2KFCVb1jOMUqlgVsMnhveAUAInVA9AuuJSSZ6D2019gkwvuELd2+CJ1hnQpXcebeRskXI4ZuQ09txPqQppZdSqxHt0JFQIH/NLXQ9xvE83bfmgKI7J4R9f8Mijv1mODfQwsdGtZtYLm0NvIS00UfRozyGIGUKPGuxjuDR9kqzyw== 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=3HCiqpwJy3Y0NvcXu4dw+pH81U/5AfQMqOEVw9MtyWI=; b=aLAmanjWojAh90qYkt4BRpSAYe48dOVqMWiRSo3fbT1ewCNDhPJxaFEHEhHzt09Y7Rq/rEndhQ5hB6pwo/1jBodCRFz2eCy7Rp1ftlqeSo/ohl/Aponetc9fVHdtkJpibpttmz/b6WQiW/pf2QXqVM9A4M69TCVWQHUQw4gVesDbHtdNp7QwTPpgYGsGxdl+R08+X99qesmK9a8f/Sir5lrdFd8Pv2WpMGe/Y3+L310xV+k5ZmkU+/3e7yaQsS0gAWaln6oNa1piMr3ANfUg0VEkFdW6KlMzKWkYolDHTVe8MkktzN26v4n7rFrLRpcD5Ok5K7EwNp7/zunijuRuMQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3HCiqpwJy3Y0NvcXu4dw+pH81U/5AfQMqOEVw9MtyWI=; b=uQPjjEx+gKg904bri3lj+XwN73X28/IwZ50Or+UUYUiRHryodKeyRZ5VDs6wFzR+yyPtvBblb7C9AatAJ8Ql6DBa6vXD864q1nfvqohOEt0df85rV7xq6/+LIR2YgA66Wsm/Xs9UvuE1xDesoUiM6IwjTINMXBJ6w8rQEmKgM7M= Received: from BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) by CH0PR10MB5115.namprd10.prod.outlook.com (2603:10b6:610:c4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Fri, 24 Jun 2022 16:45:29 +0000 Received: from BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::a080:c357:962c:eb5]) by BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::a080:c357:962c:eb5%5]) with mapi id 15.20.5373.017; Fri, 24 Jun 2022 16:45:29 +0000 From: Alan Maguire To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, jolsa@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, mhiramat@kernel.org, akpm@linux-foundation.org, void@manifault.com, swboyd@chromium.org, ndesaulniers@google.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Alan Maguire Subject: [RFC bpf-next 2/2] selftests/bpf: add a kallsyms iter subtest Date: Fri, 24 Jun 2022 17:45:18 +0100 Message-Id: <1656089118-577-3-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1656089118-577-1-git-send-email-alan.maguire@oracle.com> References: <1656089118-577-1-git-send-email-alan.maguire@oracle.com> X-ClientProxiedBy: LO4P123CA0396.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::23) To BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 28f339d6-520d-4eae-effe-08da5600f292 X-MS-TrafficTypeDiagnostic: CH0PR10MB5115:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w0W3dnVn8LqwGMmtXVrlrzkSgT46Yd96f4CifaaOYHLxEWgGITGlEtxtN5RW+RT7/sFVWRhA3HSfL+ekzK8XWLtqb9bCtWNZ0xMHkRWYNFr55I9vdFZNBznwzWHbEX+pwOFIG9TT8wpUjzALtW+u+4Ui433AE7FPpC9ilnWu5GivdVPn5SJh3pKaUe3B7mPVW75YCHTLtwIkWyr5lqvrPADpk78Y6ef7/M/QQpyQR8DBl2o+Haj8wNvdZ9gX7vYKpZS/S/F38+0byYHI+QjGqkxPDRtS5yznUlNEHkL9DxPe8ASJ1xdypRuST4ZTk+KVmXkR8TfqWxFFXZYXcbnSf3oWuyZzT6VOqGdc0M6twDhUxXhgFyWMdJHrAvFaP/llNPUEf/NFVUXI38szsvURD/Ma7jw/57b5Wm4U/c4wKRymbYXrcFJphuyBK3uXO/cHubPotWPEMOzoD/LaB69Axql91y/2x29WcBQsfpLv1H/scAaPNau4+/eyu88FC+tk524TpG//DyUQhnEQsObZRN898df9lhiSaNoiOmNhd4WMpetTNq/rD9F28/xVgQIyfIJThCYTZT/3tzWRiLaR3q7qt+Cx4WcevPULeR8m+1sZxfkkIyoFvCTb6qzMiN91yuN38KdnsxXMb68R/FWdhLmd2zplpjh7HONjx672srLjfnRPZr3CZO5hQhPSVj8j0i3Qg6Du2w61AFnnVNFPCBeWviYWvPvxWHJ1lUegCroVElQseynu80XM/rbh07Zn8awTNgosNFcR9ht7mYiHLVAnWqsIKIF9VBNB11esy44= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB5267.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(39860400002)(366004)(396003)(376002)(346002)(136003)(4326008)(8676002)(186003)(83380400001)(44832011)(478600001)(66476007)(5660300002)(2906002)(66556008)(38100700002)(7416002)(66946007)(8936002)(6506007)(107886003)(52116002)(2616005)(41300700001)(6512007)(26005)(6666004)(316002)(36756003)(38350700002)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /71vQTuK5It4uNb8XvgQRIPQTQ0XJdYBKLcypboDP9V6VVxihUvytsS/DfOzWA+Cm7a9ZP26FP1TTEZpVKLKgjNzUyxuZVjKN1adKk0BSraov+rFNWY/bP7aicSsvAdNiXS/ZkhxR4TPrZfhvlldseHPrWTsFckjNPC5NQT0RKK7Lf2haIpaiTMYS3XPZXko0mwobZQ+hZpq4D27claweJwJhQFrndwwlkfmHrVf9aCS2RIzIQDpX9pshfzMJaOVSFWw+4NA5Xa7aaka0api5y7o1vOJckiWpqzG8cOKwQCJn3L6t/F26WSVIrv/P1xcNDL72vprWEECZUQH2zaLQ+XilkeiX1rFDcRnyq4+8dQZ8oyTUfMqES9j6g9RE7f7theaZdSj+NOpGr7chSscbCcEjUtwIP/KoYmvMVyvBUbQmvgn23Hvqt2NScGG4sFQqE5M4qWs0f/uW5XZZrpYrYhkovPXeOqX2j5mIWQIAunVpqqYaS/ckDxHcXr+9YvnwNJlfCktY0c/DvCcF7jgH/zYxb0IAsj2/c+ocwh9WjxCBmKK0o3fqovM+NVIqn1juDq4oCcv78zg2h3G3Cm+OL1Rwm76JCSMdt4OhRdQj2eEPLQf9iGzrHPjdfq35V7yFeq1e2+Hz9qIoey5SIiauEWw7APRuxzl+kw0TevNuQuLCM/GiiwY3PKWH7b0qJecimZF6CKlKsKveNQXp20eSYxbpmNNUIn6LAAGaMcSLLArzy2RybWMbzlsvU5TLfpHH/3Gl+V3uJ4PdOK+4GusTfAHx56e0NM8QnQXM/JZ4Wey26ok1NEyxiqiEZRZur1IyRpoJC0IsYjSwXmOeIL1hST/FsArreRkjGsLvEnakJVOB9Nor5flmcOefwzMXOc+QJqw+bchGpllpjfhdwOsc1ZCgEZ2N3ko6zv0SvERak5k6CLkyaUEEDKu8s0TlSE2r2Uk9hLuAN3vmOHHnHg2fC7XoyVT2CJgI56IaiKUssNW+MTUysl1O95LdTuF10UoWf9TvrCOv3FTHw6AESTJ7IZAWEU4FLXncvi1y0x7gsdb80c5f6+7lwFDCLgQbmCHagVTFG7X0B4O7t1ts8fes4ZFGWkYGdfbwtN1a3Rsst7fQr0lFodI7rKJRmORYToC05WFdP71Cqkw1Na03vUgW4ktmECq6WwWzf9OitLSvaHgA6g6EqxcPqXKfqFYt25SQ4DWudMh4O1e82qCPZ5DtoIuo8BuFY09sSCa13Yv4YlIIQJurXwKZZd/Rk/17s67diu4ERplFGtPekAiHlk1ueSgry37p2W/wpO3eq/ElHEK7oIIao+1P5A9a++lE+v2NvXXP/Me+AAJ3zszWgGjrk32JGUacJXv2Hhu46Hpgjls7Ls17iobnSqxM1RnEZ93CzalYrxSbdOhK5NInbF/o+ceymFZVsNDkTSoBGmAHyIxB76Bw9d20RiwdwrRngJO6HPZe4Mi7SPMDnnxMmJhn4RmjRJef4AmJcUZfBzGT+muPsOgMsh7bSJ6TBu84+lNquQMvXCLM2ELb2F3QaibiJdBFpsgdYOUR9gRydQBWOhfgEnLTVzZjXPJplEm/2O2 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28f339d6-520d-4eae-effe-08da5600f292 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5267.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2022 16:45:29.7769 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BFDlszoOi1r9BJx6EDKMrCLXr/f1l7p/OgTrSuK0q/kQmLSJdWUUW+OrffTECHdll6QA2cPw0jUie17bL+F2yA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5115 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-24_08:2022-06-23,2022-06-24 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206240064 X-Proofpoint-GUID: BhlkWN6hnY_0ucS9EB3RMc0v-tJOBqr7 X-Proofpoint-ORIG-GUID: BhlkWN6hnY_0ucS9EB3RMc0v-tJOBqr7 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC add subtest verifying BPF kallsyms iter behaviour. The BPF kallsyms iter program shows an example of dumping a format different to kallsyms. It adds KIND and MAX_SIZE fields which represent the kind of symbol (core kernel, module, ftrace, bpf, or kprobe) and the maximum size the symbol can be. The latter is calculated from the difference between current symbol value and the next symbol value. The key benefit for this iterator will likely be supporting in-kernel data-gathering rather than dumping symbol details to userspace and parsing the results. Signed-off-by: Alan Maguire --- tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 16 +++++ .../selftests/bpf/progs/bpf_iter_kallsyms.c | 71 ++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_kallsyms.c diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c index 7ff5fa9..1197a58 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c @@ -27,6 +27,7 @@ #include "bpf_iter_test_kern5.skel.h" #include "bpf_iter_test_kern6.skel.h" #include "bpf_iter_bpf_link.skel.h" +#include "bpf_iter_kallsyms.skel.h" static int duration; @@ -1120,6 +1121,19 @@ static void test_link_iter(void) bpf_iter_bpf_link__destroy(skel); } +static void test_kallsyms_iter(void) +{ + struct bpf_iter_kallsyms *skel; + + skel = bpf_iter_kallsyms__open_and_load(); + if (!ASSERT_OK_PTR(skel, "bpf_iter_kallsyms__open_and_load")) + return; + + do_dummy_read(skel->progs.dump_kallsyms); + + bpf_iter_kallsyms__destroy(skel); +} + #define CMP_BUFFER_SIZE 1024 static char task_vma_output[CMP_BUFFER_SIZE]; static char proc_maps_output[CMP_BUFFER_SIZE]; @@ -1267,4 +1281,6 @@ void test_bpf_iter(void) test_buf_neg_offset(); if (test__start_subtest("link-iter")) test_link_iter(); + if (test__start_subtest("kallsyms")) + test_kallsyms_iter(); } diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_kallsyms.c b/tools/testing/selftests/bpf/progs/bpf_iter_kallsyms.c new file mode 100644 index 0000000..20c8d85 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/bpf_iter_kallsyms.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2022, Oracle and/or its affiliates. */ +#include "bpf_iter.h" +#include + +char _license[] SEC("license") = "GPL"; + +unsigned long last_sym_value = 0; + +static inline char tolower(char c) +{ + if (c >= 'A' && c <= 'Z') + c += ('a' - 'A'); + return c; +} + +static inline char toupper(char c) +{ + if (c >= 'a' && c <= 'z') + c -= ('a' - 'A'); + return c; +} + +/* Dump symbols with max size; the latter is calculated by caching symbol N value + * and when iterating on symbol N+1, we can print max size of symbol N via + * address of N+1 - address of N. + */ +SEC("iter/kallsyms") +int dump_kallsyms(struct bpf_iter__kallsyms *ctx) +{ + struct seq_file *seq = ctx->meta->seq; + struct kallsym_iter *iter = ctx->kallsym_iter; + __u32 seq_num = ctx->meta->seq_num; + char type; + int ret; + + if (!iter) + return 0; + + if (seq_num == 0) { + BPF_SEQ_PRINTF(seq, "ADDR TYPE NAME MODULE_NAME KIND MAX_SIZE\n"); + return 0; + } + if (last_sym_value) + BPF_SEQ_PRINTF(seq, "0x%x\n", iter->value - last_sym_value); + else + BPF_SEQ_PRINTF(seq, "\n"); + + last_sym_value = iter->value; + + type = iter->type; + + if (iter->module_name[0]) { + type = iter->exported ? toupper(type) : tolower(type); + BPF_SEQ_PRINTF(seq, "0x%llx %c %s [ %s ] ", + iter->value, type, iter->name, iter->module_name); + } else { + BPF_SEQ_PRINTF(seq, "0x%llx %c %s ", iter->value, type, iter->name); + } + if (!iter->pos_arch_end || iter->pos_arch_end > iter->pos) + BPF_SEQ_PRINTF(seq, "CORE "); + else if (!iter->pos_mod_end || iter->pos_mod_end > iter->pos) + BPF_SEQ_PRINTF(seq, "MOD "); + else if (!iter->pos_ftrace_mod_end || iter->pos_ftrace_mod_end > iter->pos) + BPF_SEQ_PRINTF(seq, "FTRACE_MOD "); + else if (!iter->pos_bpf_end || iter->pos_bpf_end > iter->pos) + BPF_SEQ_PRINTF(seq, "BPF "); + else + BPF_SEQ_PRINTF(seq, "KPROBE "); + return 0; +}