From patchwork Fri Apr 8 22:52:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 12807263 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 A4326C433EF for ; Fri, 8 Apr 2022 22:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239969AbiDHWzn (ORCPT ); Fri, 8 Apr 2022 18:55:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239046AbiDHWzl (ORCPT ); Fri, 8 Apr 2022 18:55:41 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CE5770922; Fri, 8 Apr 2022 15:53:37 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 238LKdCC024505; Fri, 8 Apr 2022 22:52:58 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=mnnG7Q6ua2ynXRHTA4M/gltsNW5+K8aG6Vc51hNZ6i4=; b=uOXAOlMtUI3/YGTA9laLg4pp6j090utan/3pKrQ0+v7jDyHgaKHLdVVdZEtXMG9TDp9i SvroX2Gxwr+RJyQfJaA8iy9WjLhaULYhSJIjaQDtX0RjjqK9AYHboLg8AG7/upCIq9VZ EFekMxTI5YZs6EEWNr6GF2F2aHRb6IPTYlywohd1ZrtAkttYVNFTJmaPj5WdNcsVKRrK G1rMDCqQbOrqKA3qA7z/xwMRTJTuqm+aC7+x8U+59RGN1qLY5phXz3IZgns8UWv4r7la UYy6Vaq2w8zkBI+4ny+3/zCocd2fCbUnzTkw7fzaymKnRt1GH8bDPjY1S91NbB2Cujv+ ug== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6f1tgrs7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 08 Apr 2022 22:52:58 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 238MjYK6001071; Fri, 8 Apr 2022 22:52:58 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3f97uynks4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 08 Apr 2022 22:52:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aXePUanHw+z7M10lpYLnGRNIoTKGEu60qs3gyruYPtkG8Z2rxuf88IDpxfGr96A7vvIbJxb2eflDc0AsrojFvBl6kGG/EotY3gBv1k+EsMn2hXvRNIZJm3SCBsWKdf9bgtP1gYtbo/qbtSA0/OtGjt58MVIjWx8TqLidl97SfNuJrmiR+xb8yhvieZ5r/fPG3mXCHTzX3EiDNfIrfREWYQOkskLJzfWjb2TB7eCCzltDrSgvnTjvTzvu/PaXKLE8UlfvQOm6ef7ofvANvSaS8isf/CusMH4b7IhTqOr8tQI1MFTW49qOt1uChTyJVFdaS11LQAecX3xQIimYh6fsfw== 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=mnnG7Q6ua2ynXRHTA4M/gltsNW5+K8aG6Vc51hNZ6i4=; b=jOX3D7QtXzjSAoXgDCx9JmIf06rVIngLWivATeCnosk1eL/o0Q343ldr/B/nG8NmdFR9uJl8jjUpI1HEVHN8scutHmpZ+cd9JDBDBHkW9KKpfC18d/zPN/EoVJ/oK/9pSKwAVMxeRdt9l1OYv336i5lUdInfBJuW/n5Sge1xUu9EHOdaARcePAjhFUCjhPq0OOOLXa52sm2ipTDu5lX87Y3/jQXh5Sz8DFDsDskon0Pc4gf4kOkOQIH2Bzw3WS27YSv1MG/Ooa0yl1LGkLKDc/EcIZfKXbjg+qKtg1TyzsUSSTIBfA3MnhxPAK3H9bthdCDn76KGPCO//BfcmPqjqw== 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=mnnG7Q6ua2ynXRHTA4M/gltsNW5+K8aG6Vc51hNZ6i4=; b=J5QXPk7T2M47DeoRNdgfwidswW2+FMvEa9j/JagtPs6t52Y6TAQQ028MXOTLRmS++0YhDuLACTJi9uDQARg82UWyifbeeirGRa2fU/5hUpoIHY3v9mrS/phRjGcfP5IOUEt63xID63rrxZpUtewgXGGhgpmVAT3l/vZuBBC80qg= Received: from BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) by DM6PR10MB3705.namprd10.prod.outlook.com (2603:10b6:5:155::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Fri, 8 Apr 2022 22:52:56 +0000 Received: from BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::bc05:7970:d543:fd52]) by BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::bc05:7970:d543:fd52%4]) with mapi id 15.20.5144.027; Fri, 8 Apr 2022 22:52:56 +0000 From: Alan Maguire To: andrii@kernel.org, iii@linux.ibm.com, ast@kernel.org, daniel@iogearbox.net Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Alan Maguire Subject: [PATCH bpf-next 1/2] libbpf: usdt: factor out common USDT arg handling Date: Fri, 8 Apr 2022 23:52:45 +0100 Message-Id: <1649458366-25288-2-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649458366-25288-1-git-send-email-alan.maguire@oracle.com> References: <1649458366-25288-1-git-send-email-alan.maguire@oracle.com> X-ClientProxiedBy: LO4P123CA0047.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:152::16) 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: 9427b05a-56c7-41a8-c1a1-08da19b28572 X-MS-TrafficTypeDiagnostic: DM6PR10MB3705:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HMMfSOMTOyhAblETPaHJ2GYSSOY9cqfuYQ/qFkCh3K+aQd9XyQ2WtRBcIpftOZcF7vJNCIFPKXVTb1UMgcdlQu4xXKxAicPciZnI/f6TBZ0ITvM/445DW3VUeZSG0mR566PIWjC2XiLbkQi3C0VdtQyUSzpEsYCSXBiBjpzueOjmRtgWG7ugebyRVIOkVbnE5HwHGMvw5ofWeDSI+9H2NOyHUSfOYTuMw65B42s5Z5SJGZiGJ5oXCKf5Fc7gwYa9QyKAK0pYhbNY9Hh12f8Oa0loQKu0LRlX6nkeSBZsn7/6d4SuP17fEyHBsnWIrJMCR5SUE6fTHbcLXKIDGtPLFxvZUM9eJHmhvqKphmbdBc5tbgB8a3KbP3HTnDGtJ9pzx1SwneEtxS8R117aW96XfJXq/qNjLuNBsT3l2aY8ukWxnnlD/q9NCmrWvH2JT/CW9MJgHp5mxpwbAct1iyESwQ9smqy5Gfv3hWHcQu/fE7TSCUS7C1k1pBDytxzaenUH5hdzTM8jXk5wdEFJnuYrCnuFEeEeRaP36L27xwShZOsYDj/TT4GbdyAaRzOdEw5Hlfrxqm24mjTpWd4fTjaQ+ClALB0+BSTOElIYtMwZFYC3KWCrZCIIZre7+51aZW1GCisBiuxUeLA1vaxP46zNOyVEYL2DDWAQaGMTzF3EggnKa3uHsW7cPmtjBTPPGW7E4uJ07jNz6tuygmCROI94+w== 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:(13230001)(366004)(508600001)(86362001)(6512007)(36756003)(4326008)(186003)(66476007)(66556008)(83380400001)(5660300002)(7416002)(44832011)(6666004)(52116002)(45080400002)(6506007)(6486002)(8676002)(66946007)(8936002)(26005)(2906002)(107886003)(2616005)(38100700002)(38350700002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ldx6yw7jSklxFlsoS5mTQLJYdXzguTFN4jyjgYfMRd2Ds5GW01V27tUi9xse4OmNQr5cYUtVrHtOhM5Db0aH6xITPmqk7qYNVglUXMDw9F2sN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evPqJju4SVDl4YB0XNa7vhxhwY7tqK091ebIlb7j19aJgMteiEkCzzi2d3LSGC8o7ydW1k3nTsIpcqCc2YXFfYvmmvV0Yl5nzBrtg3aUjrhBt76Txeaw5odKx2Bvj98D3bWdlw17wGyPe+wePd8iaJOThW7zKHtoN3fO9A7i0B8ylqTAkqS7rcFzugQaHSIBaoLZrnDvFjKVfMzgj26NZbDhBMMk3ycHn6KHuJKLsl0oKg1bFcUHmCv7Tz9yikyzlLv1hJY7XqPS7ghwvWD2AJddSjOHfaMZZ4cIgPscLdNTIbqsDN+vsXiaAdaeb0mjRJ2Jkh5j+GGJ/nJw8YHTQuTZwHstGozdXGZvYWWjBwmE2ieSBQu1J7d5DFIUhltXrzEAJ4sMKUJe1ekYqxuk4TuSoXwqxn47hj5hHaEtFzILryXoeYVodJqBhg1e8QiH8qAmboCFZzCXPD2IVXOm68sd2f90HtiMy/B86v7FnYEhULLLGlFLINmHmBIzSDQ624IssctWiSPKtLCvT/blyl0fA/I7W4MjhViGLiKPD3obrGsrBeZVoWUxIFoqiaPwDzrkCa/DXIiac= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9427b05a-56c7-41a8-c1a1-08da19b28572 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5267.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2022 22:52:56.1984 (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: lcNLqpeVot+/nMqQAt+vcsuhF0krxD2m6hgv7aVmHimAFpSJPLCU0ZRj5xzGwEPuGuo/ZrOtQNVSVYQkYAEZKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3705 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-08_08:2022-04-08,2022-04-08 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204080117 X-Proofpoint-ORIG-GUID: kSGldJClv2XQ1vd3zBpf8UKgQBFPJOUa X-Proofpoint-GUID: kSGldJClv2XQ1vd3zBpf8UKgQBFPJOUa Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Common code to initialize a struct usdt_arg_spec can be factored out from arch-specific flavours of parse_usdt_arg(); signed size, bitshift handling etc. Signed-off-by: Alan Maguire --- tools/lib/bpf/usdt.c | 90 ++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c index 30c495a..0677bbd 100644 --- a/tools/lib/bpf/usdt.c +++ b/tools/lib/bpf/usdt.c @@ -1170,6 +1170,31 @@ static int parse_usdt_spec(struct usdt_spec *spec, const struct usdt_note *note, /* Architecture-specific logic for parsing USDT argument location specs */ +#if defined(__x86_64__) || defined(__i386__) || defined(__s390x__) + +static int init_usdt_arg_spec(struct usdt_arg_spec *arg, enum usdt_arg_type arg_type, int arg_sz, + __u64 val_off, int reg_off) +{ + if (reg_off < 0) + return reg_off; + arg->arg_type = arg_type; + arg->val_off = val_off; + arg->reg_off = reg_off; + arg->arg_signed = arg_sz < 0; + if (arg_sz < 0) + arg_sz = -arg_sz; + + switch (arg_sz) { + case 1: case 2: case 4: case 8: + arg->arg_bitshift = 64 - arg_sz * 8; + return 0; + default: + return -EINVAL; + } +} + +#endif + #if defined(__x86_64__) || defined(__i386__) static int calc_pt_regs_off(const char *reg_name) @@ -1220,52 +1245,32 @@ static int calc_pt_regs_off(const char *reg_name) static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg) { char *reg_name = NULL; - int arg_sz, len, reg_off; + int arg_sz, len, ret; long off; if (sscanf(arg_str, " %d @ %ld ( %%%m[^)] ) %n", &arg_sz, &off, ®_name, &len) == 3) { /* Memory dereference case, e.g., -4@-20(%rbp) */ - arg->arg_type = USDT_ARG_REG_DEREF; - arg->val_off = off; - reg_off = calc_pt_regs_off(reg_name); + ret = init_usdt_arg_spec(arg, USDT_ARG_REG_DEREF, arg_sz, off, + calc_pt_regs_off(reg_name)); free(reg_name); - if (reg_off < 0) - return reg_off; - arg->reg_off = reg_off; } else if (sscanf(arg_str, " %d @ %%%ms %n", &arg_sz, ®_name, &len) == 2) { /* Register read case, e.g., -4@%eax */ - arg->arg_type = USDT_ARG_REG; - arg->val_off = 0; - - reg_off = calc_pt_regs_off(reg_name); + ret = init_usdt_arg_spec(arg, USDT_ARG_REG, arg_sz, 0, + calc_pt_regs_off(reg_name)); free(reg_name); - if (reg_off < 0) - return reg_off; - arg->reg_off = reg_off; } else if (sscanf(arg_str, " %d @ $%ld %n", &arg_sz, &off, &len) == 2) { /* Constant value case, e.g., 4@$71 */ - arg->arg_type = USDT_ARG_CONST; - arg->val_off = off; - arg->reg_off = 0; + ret = init_usdt_arg_spec(arg, USDT_ARG_CONST, arg_sz, off, 0); } else { pr_warn("usdt: unrecognized arg #%d spec '%s'\n", arg_num, arg_str); return -EINVAL; } - arg->arg_signed = arg_sz < 0; - if (arg_sz < 0) - arg_sz = -arg_sz; - - switch (arg_sz) { - case 1: case 2: case 4: case 8: - arg->arg_bitshift = 64 - arg_sz * 8; - break; - default: + if (ret < 0) { pr_warn("usdt: unsupported arg #%d (spec '%s') size: %d\n", arg_num, arg_str, arg_sz); - return -EINVAL; + return ret; } - return len; } @@ -1276,51 +1281,38 @@ static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg) { unsigned int reg; - int arg_sz, len; + int arg_sz, len, ret; long off; if (sscanf(arg_str, " %d @ %ld ( %%r%u ) %n", &arg_sz, &off, ®, &len) == 3) { /* Memory dereference case, e.g., -2@-28(%r15) */ - arg->arg_type = USDT_ARG_REG_DEREF; - arg->val_off = off; if (reg > 15) { pr_warn("usdt: unrecognized register '%%r%u'\n", reg); return -EINVAL; } - arg->reg_off = offsetof(user_pt_regs, gprs[reg]); + ret = init_usdt_arg_spec(arg, USDT_ARG_REG_DEREF, arg_sz, off, + offsetof(user_pt_regs, gprs[reg])); } else if (sscanf(arg_str, " %d @ %%r%u %n", &arg_sz, ®, &len) == 2) { /* Register read case, e.g., -8@%r0 */ - arg->arg_type = USDT_ARG_REG; - arg->val_off = 0; if (reg > 15) { pr_warn("usdt: unrecognized register '%%r%u'\n", reg); return -EINVAL; } - arg->reg_off = offsetof(user_pt_regs, gprs[reg]); + ret = init_usdt_arg_spec(arg, USDT_ARG_REG, arg_sz, 0, + offsetof(user_pt_regs, gprs[reg])); } else if (sscanf(arg_str, " %d @ %ld %n", &arg_sz, &off, &len) == 2) { /* Constant value case, e.g., 4@71 */ - arg->arg_type = USDT_ARG_CONST; - arg->val_off = off; - arg->reg_off = 0; + ret = init_usdt_arg_spec(arg, USDT_ARG_CONST, arg_sz, off, 0); } else { pr_warn("usdt: unrecognized arg #%d spec '%s'\n", arg_num, arg_str); return -EINVAL; } - arg->arg_signed = arg_sz < 0; - if (arg_sz < 0) - arg_sz = -arg_sz; - - switch (arg_sz) { - case 1: case 2: case 4: case 8: - arg->arg_bitshift = 64 - arg_sz * 8; - break; - default: + if (ret < 0) { pr_warn("usdt: unsupported arg #%d (spec '%s') size: %d\n", arg_num, arg_str, arg_sz); - return -EINVAL; + return ret; } - return len; } From patchwork Fri Apr 8 22:52:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 12807262 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 239E0C433FE for ; Fri, 8 Apr 2022 22:53:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235811AbiDHWz2 (ORCPT ); Fri, 8 Apr 2022 18:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237230AbiDHWz1 (ORCPT ); Fri, 8 Apr 2022 18:55:27 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 186D7A146D; Fri, 8 Apr 2022 15:53:22 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 238LH6Af014737; Fri, 8 Apr 2022 22:53:05 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=/Gifo4HUYQyLLitYneboX59wA8qb9JybsgkPe1cyx60=; b=xdz1DCO2DSl7oKIqg/ZjQOHm9Ht8eGZ1g1x1QxaEVUUDhunWVtEMUyH4mkfuMe5F5ZAe zkoTtRJrhskCQHZTYUcN3hZyDBjQ/uu/XRqjPpohoiGiKm8YbYhSwVc2YI7jPJ+i7ohe 6G5YxGoB/2G++CwAkUGqiZaQF4+iHZz3584DV+kSstIlJyJv5btBrY4iMhnEKjVpE9DY oLbjNHKvdwDg7PefOEApWEIfadpPJbnNcG8QdBZPDXYUP58E5b7zRK396C/rllL33Dhf VTTAxPMuSlPgespeYFXFG+SDYeWmKYPERaLEN7iIBjQxK7J2iPKrsmc5jq2JD+3X0BAn UA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6ec9yxcp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 08 Apr 2022 22:53:05 +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 238MkvLv029275; Fri, 8 Apr 2022 22:53:04 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3f97y9e12s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 08 Apr 2022 22:53:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dcS5d7GkDRy4Rb1IcEKd+mQ+srbEiNhY8MSuycF0yuQbsfN4Hin70xnNcHe9RM2gqcXjOId01NSak6G9NeM2iMNpnPvxCe2Es+EZ5SCNHm3YsaxY6a3ZEelw+npXTWg08WzYwe927kM5vyWqtB3HBZk35tocvWPkpXxpCvGaGISyPWQH3CN3e9eIZ4iuGtkpdHqsa7UKA77ynx4K6j/HSfCZQrEb55is3M3saZYT37IovPW5gTN/gzv+xT9egyQyHaqqapDCWKILmlhzCpx8J4QOgmlxsj67T8U7NOBVgb3d151u5pikyTJi6Qtr5ck+FHoUengFbD5m92GTPfuVzQ== 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=/Gifo4HUYQyLLitYneboX59wA8qb9JybsgkPe1cyx60=; b=VXCOw06+CTmbXBJPBGHsQzONqpN0u/cnqsfdNNTKCi/vL27RhJI/6bwc2Cnu5VJ4vYP+dQM4ip7EXD6Ux3NQEGuFPQoRhkkY5uTcaY7sCqtbnOqm5f7okHXR1bIxqeymGLVV/GFZcY5N5cItPRgYPNx2036OL+pC1hiR1Y1+5XurLC2sR7GO89+bmFS3HvtV3JUeVy8fPrFklI5PZ7HTYFBk64uryYWrb7u8qpVGeO6ll0sJGwceel727hz5OOTLkE2XZRVrkV737iXoMgDxXSmgjBP+sax0lB0HVvONG0KaxNgKI0zb/nS7mkzA+mMvPdc5H+eoj/GO6zg6eNN9Cg== 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=/Gifo4HUYQyLLitYneboX59wA8qb9JybsgkPe1cyx60=; b=Ycdxlb+MsnJ4URqRgVrxOOgDRAfcxAdIPf1fjyXwvwu5Gwm3Z2tJLi8dhKIMcZvSr+K8Ou+Y72qzduvVrupEIAVthnGgM/rTyE1tgLrqQVhxuS2ZSrzwtkO7+qEuTWoPYyc35e/Yg4U3j91boPgooyUu/sfU02oGQjf/Qkr8c6s= Received: from BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) by DM6PR10MB3705.namprd10.prod.outlook.com (2603:10b6:5:155::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Fri, 8 Apr 2022 22:52:58 +0000 Received: from BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::bc05:7970:d543:fd52]) by BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::bc05:7970:d543:fd52%4]) with mapi id 15.20.5144.027; Fri, 8 Apr 2022 22:52:57 +0000 From: Alan Maguire To: andrii@kernel.org, iii@linux.ibm.com, ast@kernel.org, daniel@iogearbox.net Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Alan Maguire Subject: [PATCH bpf-next 2/2] libbpf: usdt aarch64 arg parsing support Date: Fri, 8 Apr 2022 23:52:46 +0100 Message-Id: <1649458366-25288-3-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649458366-25288-1-git-send-email-alan.maguire@oracle.com> References: <1649458366-25288-1-git-send-email-alan.maguire@oracle.com> X-ClientProxiedBy: LO4P123CA0047.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:152::16) 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: b17a5588-9580-4b04-1eee-08da19b28679 X-MS-TrafficTypeDiagnostic: DM6PR10MB3705:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E+yFKNFBK0wchcKAKxcqwP2LtO6Iifv37vDWxHUFnrdf9E5TxEBQbt7E5s2OaoMCXuE7RaH4NEgbDbuen28RNgs2bIAo8KrcuZ1+WKuSVfxN1r5tK14fvUFBTTg7HNCGW1XqJ41RjOIuspjDaShGWvbjhFf+0JU7kCnewp0qS6aHxKDaHF2i4EKWss8VFAwVRIkkn52zokMYbmexBKZfesHPToDnGCvAn5OpN9ULwA5I62k1ULc+1D3H4K4CQqtQCg9dMWLP/l7oMdTWUvZTOQDT+JRh7Ia8ldBoHzPuP1k9QaSK37FAWeloJx1utzNsgQpj0Oxvw0YHhqPjbBJCWCJ/kCzeAOOLvRtR1amZza92wY75O6HFozCMWRhwHaxrhgJpgrPGKXl7PyfsaF4fAH9WkSQKqZ+IK3554p3IM0XyaT4yvovz6chFWnfxnPo5X01Wqmw0s5Duw+s7P9BZ5gnSpogI9enaYKgq0lUCdFEEhkryo3qG2YvzNYSX6gh16G7J/S27RWMgXnm7nfI7Jzvm9I5s8P/PGlpnDri4EqsBsOQrdULkL0b8w7k7YoL2zuKfNPxhogQWQO+NJydOq4CxZK4MKA8Lc93HbU7X7Uofr8duRK87oPXUB81w1lNRFYS5m6L5edw+QnWp+VBWWUVj+29+odar5p2lPubL19ZFdDnJN+D73aB9kWAWH4HYFo5fIFDhtF9UooQjkZnP8g== 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:(13230001)(366004)(508600001)(86362001)(6512007)(36756003)(4326008)(186003)(66476007)(66556008)(83380400001)(5660300002)(7416002)(44832011)(6666004)(52116002)(45080400002)(6506007)(6486002)(8676002)(66946007)(8936002)(26005)(2906002)(107886003)(2616005)(38100700002)(38350700002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +ppRVRH3RFLY6p3tymRQSMbzz+qxuSCC/DptzUKivPPvr8crBNRy30GaAvGGmyZ72mA8zfF1kiDwkxPLJ3YgJu45PFnfq5ctOyYh9eXtbq86fCL1Plg63QTh4xyiA81NiZZUZWRQGX0KnA39gjYaIG1qQLwCAR6stj45d96hW2KIxVuYla9i5b+p1k0HJ1I/Dh6M4O2exugPIQEnlZQhX8QU/o8eSx0oINEd1E8vX/FCF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soNubFd0JS7RjPQwl+HJHp0unmTkCfAYnsX42NwisnjdHQ9RBSKJxEL1jNpZmeaXXunOObESRA0Wl8h/EJJGZ6TRK8tB04VOZ6t0d7yzMhDa/9sCQ8kfPea7BaF9XqHN68w0bVBZfUNgSI4bh8W62OUGNzU1uByVtYAzQYx64fjrGIKDLZuGv2vaan1LQOynydKhp7ahQM7P7xGZZsUpdCbkzsaDM4d8fhMwA7vRfDPzNpPZjemJayoo8Ai1iRZZE+iVSCACBAYsGp3z2vlLGy51lLEtyGpUCaj6/LlQVW8Xrrwr0iy1/dzNq4sK2+prm91UeHFTHMQONymdBeSlo9lS9Ld+HpjW+HVT6njHjqrndjKj2WzOWavNo3xDQpqB6w4R83ZVfaSHoykiVrpmxM67v3Ae2hRb2uKZeqVyy+DS/GFiiyCbW7dOryXRske47V9nrLiSihlewko= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b17a5588-9580-4b04-1eee-08da19b28679 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5267.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2022 22:52:57.9178 (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: iBwgQNdolp5LUlMTh+N1liH/h4V7OUxzaCzlaFYtmn6ZoZHcs+lbY36/5z/AkunMW/UJOREAjET+5y8NCt3aDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3705 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-08_08:2022-04-08,2022-04-08 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204080117 X-Proofpoint-GUID: JfRCckjuKKVthWUSawCk_EoIjENMhQaw X-Proofpoint-ORIG-GUID: JfRCckjuKKVthWUSawCk_EoIjENMhQaw Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Parsing of USDT arguments is architecture-specific; on aarch64 it is relatively easy since registers used are x[0-31], sp. Format is slightly different compared to x86_64; forms are - "size @ [ reg[,offset] ]" for dereferences, for example "-8 @ [ sp, 76 ]" ; " -4 @ [ sp ]" - "size @ reg" for register values; for example "-4@x0" - "size @ value" for raw values; for example "-8@1" Signed-off-by: Alan Maguire --- tools/lib/bpf/usdt.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c index 0677bbd..6165d40 100644 --- a/tools/lib/bpf/usdt.c +++ b/tools/lib/bpf/usdt.c @@ -1170,7 +1170,7 @@ static int parse_usdt_spec(struct usdt_spec *spec, const struct usdt_note *note, /* Architecture-specific logic for parsing USDT argument location specs */ -#if defined(__x86_64__) || defined(__i386__) || defined(__s390x__) +#if defined(__x86_64__) || defined(__i386__) || defined(__s390x__) || defined(__aarch64__) static int init_usdt_arg_spec(struct usdt_arg_spec *arg, enum usdt_arg_type arg_type, int arg_sz, __u64 val_off, int reg_off) @@ -1316,6 +1316,54 @@ static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec return len; } +#elif defined(__aarch64__) + +static int calc_pt_regs_off(const char *reg_name) +{ + int reg_num; + + if (sscanf(reg_name, "x%d", ®_num) == 1) { + if (reg_num >= 0 && reg_num < 31) + return offsetof(struct user_pt_regs, regs[reg_num]); + } else if (strcmp(reg_name, "sp") == 0) { + return offsetof(struct user_pt_regs, sp); + } + pr_warn("usdt: unrecognized register '%s'\n", reg_name); + return -ENOENT; +} + +static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg) +{ + char *reg_name = NULL; + int arg_sz, len, ret; + long off = 0; + + if (sscanf(arg_str, " %d @ \[ %m[^,], %ld ] %n", &arg_sz, ®_name, &off, &len) == 3 || + sscanf(arg_str, " %d @ \[ %m[a-z0-9] ] %n", &arg_sz, ®_name, &len) == 2) { + /* Memory dereference case, e.g., -4@[sp, 96], -4@[sp] */ + ret = init_usdt_arg_spec(arg, USDT_ARG_REG_DEREF, arg_sz, off, + calc_pt_regs_off(reg_name)); + free(reg_name); + } else if (sscanf(arg_str, " %d @ %ld %n", &arg_sz, &off, &len) == 2) { + /* Constant value case, e.g., 4@5 */ + ret = init_usdt_arg_spec(arg, USDT_ARG_CONST, arg_sz, off, 0); + } else if (sscanf(arg_str, " %d @ %ms %n", &arg_sz, ®_name, &len) == 2) { + /* Register read case, e.g., -8@x4 */ + ret = init_usdt_arg_spec(arg, USDT_ARG_REG, arg_sz, 0, calc_pt_regs_off(reg_name)); + free(reg_name); + } else { + pr_warn("usdt: unrecognized arg #%d spec '%s'\n", arg_num, arg_str); + return -EINVAL; + } + + if (ret < 0) { + pr_warn("usdt: unsupported arg #%d (spec '%s') size: %d\n", + arg_num, arg_str, arg_sz); + return ret; + } + return len; +} + #else static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg)