Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2899754rwb; Fri, 2 Dec 2022 17:28:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf6L2ANOVJa64SE+dQYTDPQOr99/WzYshLG5y2VpK29ewbWzUI38W7Y74OlV3UUx4Wwh1zvp X-Received: by 2002:a17:902:eb13:b0:189:44a2:4cb0 with SMTP id l19-20020a170902eb1300b0018944a24cb0mr49385417plb.44.1670030896568; Fri, 02 Dec 2022 17:28:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670030896; cv=none; d=google.com; s=arc-20160816; b=E6C5bVWjGFl0oYa2lNifMj3qW79G9Os0ojLE0ptg1MvtvxYlJx6Wtc+EKOOUbUwtrO boacL13dnBUZvxCYnqQ8ZqpuOm0cOtGW8VxYw9STAkasQuIITLFMbsY+6GEg+CTT+W2K 3r6s1axXm16VcXnGajrNhJrNz5IEqjW3QNu9vPheTestEblKiQENBh9f3JQroa3vIiaI pQbwJ9+sR2/OMrHSiqQU3JBqs+14+CIpH1mE1+xK5T1FlaxVy+4ui9g7LvFGJpXgu5lU ZjUmeIII/aQJy1vm4m4G0kk98xjDSiIvj0qs7z9EDkaKs4Jz5Ekycp5mvqrt/ndM3JTY TcSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ETGHnnHIgxVXTPrH41fr6V5n9u5cAImypbTy8FSNQvE=; b=0xacOOiN/SnuykKU1t7sAdjWez+Hi1XWGDQuextiH2ZKGKYo/1kWIMS8zvHuWDe02z Nl+OOzlX+6PHV3bDE9LcMfzO+MEiyuuG9qkITMa0CMf7atoBSbvYu/C4EIf6Ix2KtNYn oMq3bWcv0RFPzbl89EptdJihsKvYtW1fs/Es9bK2U9JZy7azvVle/QY8mepj5RXKGXLQ EhvvL6yFeIE5w9K/sKalK+PmgRrFovc5legk2EWbNxVh2nOkWFlnxVyxsh+jZPy7xnKj m0URQymEKj5nKRkPpWxY3qriNMdg/De9jRCi4okytBT7BFQqKMF1T4DjuabjYWclaiAn wsWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gZbkLKMK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g22-20020a632016000000b0046b3ba2c806si8120629pgg.145.2022.12.02.17.28.05; Fri, 02 Dec 2022 17:28:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gZbkLKMK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235325AbiLCApj (ORCPT + 82 others); Fri, 2 Dec 2022 19:45:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235269AbiLCApT (ORCPT ); Fri, 2 Dec 2022 19:45:19 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36959FB89F; Fri, 2 Dec 2022 16:39:25 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id vv4so15101024ejc.2; Fri, 02 Dec 2022 16:39:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ETGHnnHIgxVXTPrH41fr6V5n9u5cAImypbTy8FSNQvE=; b=gZbkLKMKM3PWDeS7TFmqS8aTdK1AcZgh52X9w6XbiC6g2MpbdBbVfcMOp9Gm22JJpo yBXRe6pbM6oG+VNyfrVkXSASYlnyrzsuuXgpciNQEE4LEr/7BIBRkGNcMdnNEUkAcVbE 62MMuINAOAxO5W65oqWQhs3XMgOy0exKGQHSqX4U9K4n/lrxz859XgKiK94V4ffSoUlr 300UVAN9/l06mFDeTn0AufpU/wqD2F7/4dKf12P2eBV/JHMDwgrM+SfZVaM9E7UdSE8L tfdzuKo0HaXgz2ebn/sbTdDZ0NupufwWjARcWA+XP1gGi4CfDpHzGMLahQTUX7pIgKkQ myFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ETGHnnHIgxVXTPrH41fr6V5n9u5cAImypbTy8FSNQvE=; b=0d2uGRgKoQSbdr5G0nbyVPHAkC2DP+r+oXHu93FzRoN1rANrXCZ0O+wnjMk2wNf12X DTWm6C++jmDN9cM37sWiUK6S5AzHuEq4KiR2qqJlHW4QTaxu8sPk2MGuhCj33diYYgX0 zXP2fSAffN+1moSkEr/gfSWjHi5DXBm2x8mXUGp3YW1Vz7lofDntDou736KgmKRe8Wvf fTI1Ge9P69xsNmJ/EFsccCyX40KSEBiLW8DWCwaFxGo9Eep7+2pufGV1MiSRabqAmaY1 N+rYX4sJCnKN9Fr/aWRdTHxSvplGxg1lXlXsfGx6CmxgR7t0VCZrWBRpN27flXHWMmTL 0lVQ== X-Gm-Message-State: ANoB5pkAvFftCZyukeRg4DV9FZ2p37FGu+QZzYaAcMZGYTkV4yKnNbB3 d6P+ZLH8SmAPYpMBi74jxgLULFghHX+9Es85riw= X-Received: by 2002:a17:906:414c:b0:7a9:ecc1:2bd2 with SMTP id l12-20020a170906414c00b007a9ecc12bd2mr50717390ejk.545.1670027963525; Fri, 02 Dec 2022 16:39:23 -0800 (PST) MIME-Version: 1.0 References: <20221202153816.1180450-1-timo.hunziker@gmx.ch> In-Reply-To: <20221202153816.1180450-1-timo.hunziker@gmx.ch> From: Andrii Nakryiko Date: Fri, 2 Dec 2022 16:39:11 -0800 Message-ID: Subject: Re: [PATCH bpf-next] libbpf: parse usdt args without offset on x86 (e.g. 8@(%rsp)) To: Timo Hunziker Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@google.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On Fri, Dec 2, 2022 at 7:39 AM Timo Hunziker wrote: > > Parse USDT arguments like "8@(%rsp)" on x86. These are emmited by > systemtap. The syntax is a mixture between the "memory dereference > case" and the "register read case" as the offset is zero but the > register is wrapped in parentheses. We treat them the same as the > the "register read case". wait, why? I'd assume this is equivalent to 8@0(%rsp) and that's actually the USDT_ARG_REG_DEREF case? I.e., we read the value of %rsp and then use that as a pointer to a memory. > > I've tested that this fixes the "unrecognized arg #N spec: 8@(%rsp).." > error I've run into when attaching to a probe with such an argument. > Attaching and reading the arguments works. > > Something similar might be needed for the other supported > architectures. > > ref: https://github.com/libbpf/libbpf/issues/559 > > Signed-off-by: Timo Hunziker > --- > tools/lib/bpf/usdt.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c > index b8daae265f99..5e7ec7ad8ad7 100644 > --- a/tools/lib/bpf/usdt.c > +++ b/tools/lib/bpf/usdt.c > @@ -1233,6 +1233,14 @@ static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec > if (reg_off < 0) > return reg_off; > arg->reg_off = reg_off; > + } else if (sscanf(arg_str, " %d @ ( %%%15[^)] ) %n", &arg_sz, reg_name, &len) == 2) { > + /* Register read case with parentheses, e.g., 8@(%rsp) */ > + arg->arg_type = USDT_ARG_REG; while you implemented it as "return %rsp value", it's a very different case > + arg->val_off = 0; > + reg_off = calc_pt_regs_off(reg_name); > + if (reg_off < 0) > + return reg_off; > + arg->reg_off = reg_off; > } else if (sscanf(arg_str, " %d @ %%%15s %n", &arg_sz, reg_name, &len) == 2) { > /* Register read case, e.g., -4@%eax */ > arg->arg_type = USDT_ARG_REG; > -- > 2.36.2 >