Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10607153rwl; Wed, 11 Jan 2023 23:34:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXsNoQmpxsdCRao7yF7i/4xUDfo8Vd8RPVSLxDuGsssVaWsk45BOHnEx5KWa/qBum+2biDou X-Received: by 2002:a17:907:d50e:b0:7c1:5982:d729 with SMTP id wb14-20020a170907d50e00b007c15982d729mr74891185ejc.56.1673508878823; Wed, 11 Jan 2023 23:34:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673508878; cv=pass; d=google.com; s=arc-20160816; b=vM43mXXvSuWL1QER/Jv7YHVvPuw5+m27eKCAX3Rs98tc9pl71gixX3YTsOCl+trjoL 4euDEl7449sptWG1ImoPZLcCW6ppy5XBWBdsWds2T6GatKIRbFpWS2OoULHvG7R9XDzF aS/CnJn5eGS/ibuRVsMsKamzdRItF0wBJVfdMNv59SSKJjkCY4yQ09qSGr+7tDTl81tP tCX75oCyL62PQPQca3+WQa90v8WDsbHuh+oLgnSIyp+lBiCGWRO8xLHas8WNsxSBWh41 4mrt3YPEr6nKpsnYvkWyk1QC8n7w0Csb8UHPU3F4p7wpT0EvUu/TcTr/vGbYYIMEePmR R0jQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=VjR7h8IAyClrxhM4NfWWqOBSSxb4SJoHWwWm9xPXoCo=; b=HlwCM1XKa5qB3U85c9zYbVhvjZHns2BTT6MtyzTwa7MZcMqtPznDqZHOGNtls5M5vP oiWXAttQEJdgp6+4qQKK0wvF9ozIT1xJzFpSlppu8PxYA81D2Y8fx+QneElJvh3uXW8p b2lcJF/dD0qZ/izmivBZl8WWETGOzhci417nyTZW/+fJxFzJloBF9BZVT3U7mhl7MlJh uVc/8dEALKAivlnGbKjNKVWZlcE6FY2Mg8oooMf5JEycRwDP0c0OWflI01sP6LtTxfyl dkESQL/fenJYAVYN3Aif8NhJfC/u5CnaHE8N+Thz2deiZ7cMyGr95ugMHHhPUtQHQ0FG hGeg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@meta.com header.s=s2048-2021-q4 header.b=Wz1em0gW; arc=pass (i=1 spf=pass spfdomain=meta.com dkim=pass dkdomain=meta.com dmarc=pass fromdomain=meta.com); 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=REJECT sp=REJECT dis=NONE) header.from=meta.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho37-20020a1709070ea500b0078db719e54csi20269339ejc.98.2023.01.11.23.34.26; Wed, 11 Jan 2023 23:34:38 -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=@meta.com header.s=s2048-2021-q4 header.b=Wz1em0gW; arc=pass (i=1 spf=pass spfdomain=meta.com dkim=pass dkdomain=meta.com dmarc=pass fromdomain=meta.com); 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=REJECT sp=REJECT dis=NONE) header.from=meta.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235407AbjALHYQ (ORCPT + 50 others); Thu, 12 Jan 2023 02:24:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236436AbjALHYI (ORCPT ); Thu, 12 Jan 2023 02:24:08 -0500 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0097D186D8; Wed, 11 Jan 2023 23:24:06 -0800 (PST) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30C5iAlk013545; Wed, 11 Jan 2023 23:23:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=s2048-2021-q4; bh=VjR7h8IAyClrxhM4NfWWqOBSSxb4SJoHWwWm9xPXoCo=; b=Wz1em0gWx4z3w6zTkJzupZ4qYpJj06QGz6QtI5o8TN106SBcRku/dLeH47Lr7RBsn2le +1aaWf7p/FwiDK1/msljzug4d3JIqNg1mNRizCB0IURysGCFv2I2kIjNuYJEgebF+8Kz /cc4+VAM1mkhSPnffYukU5nqp7d4bQev/qkxcvFOZv+sn0uUuQuq6D19m1PbI95OhJjq +KHmuXokgEc0lbR+DhH6bxAqCMkiyaMIumiy5q+7NPRelD2frC27f60xD3H+9BLcyWEW ySd0nnE/0fcuv3RZ2WP1IrdbWDtz73wsKoBts9QZz7Fa0OiNMYvtMzmU/hwKGzqZf8g8 2Q== Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3n23bpt1fx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Jan 2023 23:23:21 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SDnpVmLBnvHEdfysCbqr1Nf4zKJqebNt90yh8HtzHpRQQQhX+1MsMGrMfkrIBExGpaJD4ZWd04mbSkZ3OHskOn6uE5tZXdccbraMoPUEGhmc/ocGZEfINHUBmufbNtxaib3+RAUJ7dW6OtUbn3lx11Z3j1PNtpG86M24yvFHxLI4UePjs5sNh50v4+Lf/6fWjsfWrNc4BEdN/fRYnPqo9WW4RY/vSSGHWGsjchYljcn4pAWy11EUqNg2zsdl8cNjz5ogNBITjKx5Y+q89CKWZeGlsSD+PBQAneLkYqSl+8k8tYTFLTCcwVXaN1SuG6wLO1c4hBzkq6IuEfSg/5KVeA== 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=VjR7h8IAyClrxhM4NfWWqOBSSxb4SJoHWwWm9xPXoCo=; b=n69633tQofvSJPylp/xZX0O+AIrMif5j5zuUaHadhAUZhlBFR37PJ91T+MTnpgHz+1IgsAjrPGAtmvOyQmBDgVZzagfeSrfGcDgQHagBFf27uJ2OoXUOHV0yK0xDL0bp1CurogsFrrjuxYLSZ/pyvl5j1GVVVSs0Lcpo0wBAXXgzUjTdbmdCaNAr+jKR+4pMh6nvyGPk+fi601dYs5xaY7G5JjWEK3EOO1uJKBFUYsIReEhZ43G/63M0dlNdMSZX0+coJE8TeJh5w03M7ocSrcuQj2wMDBXzRT+08G57TRSBByZc0AdAd48QTJF5cttQTwshNncSRTgZOyW/tZfPbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=meta.com; dmarc=pass action=none header.from=meta.com; dkim=pass header.d=meta.com; arc=none Received: from SN6PR1501MB2064.namprd15.prod.outlook.com (2603:10b6:805:d::27) by PH0PR15MB4463.namprd15.prod.outlook.com (2603:10b6:510:84::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Thu, 12 Jan 2023 07:23:19 +0000 Received: from SN6PR1501MB2064.namprd15.prod.outlook.com ([fe80::3cc9:4d23:d516:59f0]) by SN6PR1501MB2064.namprd15.prod.outlook.com ([fe80::3cc9:4d23:d516:59f0%4]) with mapi id 15.20.5986.018; Thu, 12 Jan 2023 07:23:19 +0000 Message-ID: <6c14e7ad-3b6d-4f88-64b8-8e3968d2b2e6@meta.com> Date: Wed, 11 Jan 2023 23:23:16 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] libbpf: resolve kernel function name optimization for kprobe Content-Language: en-US To: Menglong Dong Cc: daniel@iogearbox.net, ast@kernel.org, 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@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Menglong Dong References: <20230109094247.1464856-1-imagedong@tencent.com> <504cc35a-74a8-751a-5899-186d7a0aff87@meta.com> From: Yonghong Song In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SJ0PR03CA0075.namprd03.prod.outlook.com (2603:10b6:a03:331::20) To SN6PR1501MB2064.namprd15.prod.outlook.com (2603:10b6:805:d::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR1501MB2064:EE_|PH0PR15MB4463:EE_ X-MS-Office365-Filtering-Correlation-Id: acd213bd-490f-4f28-ab19-08daf46de0f3 X-FB-Source: Internal X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wGCjGJTpQhv1mCpyC6luOM539FG+w1NtYTvTgsPjliyiatR5/R2a/2WTA5eqwYPNDkckRHgylR/g03rtHwx3FOU0nBKM/sVlHIp8S9JFCcZU2tPLswUNmhP2kfsWamUhJqDCtyDDFh1dvJJmssZGaCDN4nwyJL4CVSunyk/5KV4jULPpp2rSSZYCmVlM96bEIeCgQk2UtJ93t55GRIr6qUpEFxX+DkLJy0WoCBwNqJnn/8uGeGr7s+F6L7GiOOCw26Mr6vJA4zi77vLBVoAPdXMqB9mDmiaF05/vBVsCWFgPUvdAIikGWdtshBM76EshPo1xP8AXh5M+h2oKIwGXnwikkPL+jHGJX370NBeIdOwJebe+UfGio5CkdeBEX40RfZhUHBDCwhJM2JltBnSVgukxGY7BiIUvSbxj2/Pvek/Dddmmk1KvXLRAWPjhMoSCp5CANwRroeCsflYurQLylLuorlDAbmyeyyWveC12bZvUIEs5z/qACXajdancV50JHVPCC91sSmw9fzOJXWhl2kXgRN3EmXk4fSfYN33ub5iaQ4GMiovu1UWhfXMGSYJCXBo6aDAUiOWaEjBs72eD7iV10HyZD5O22NHmmvICBtBva4gcXS92lMbyfV4prpf5XYAN+RJL9L/c1NuRVQMLga5jodKNYlXs810OIwho6pTRq9syPQNnzluIvBmeG0dK3QVrDoJUsWOJTqNETUJJQISGL2LAQXdAKwf6AGKu8eAYFuSSDcdzh1LObphH1OHJ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR1501MB2064.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(136003)(39860400002)(366004)(346002)(376002)(451199015)(66946007)(66476007)(4326008)(66556008)(8676002)(6916009)(316002)(5660300002)(2906002)(8936002)(41300700001)(7416002)(53546011)(36756003)(31696002)(83380400001)(6486002)(478600001)(6666004)(6506007)(38100700002)(2616005)(6512007)(186003)(31686004)(86362001)(66899015)(21314003)(43740500002)(45980500001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YUNNQSs3QlZPLzBhR2VMaW9wMjF0NmRtUWUxVzF6cjdqZm1FenFkUi9uY3NG?= =?utf-8?B?YWt4ZmNzQnd3SDZjam9NaT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?RFdMamlvYXhQTjBkMWhrYkxnQmExS3NrS2dHUzlrUDJVZGdUemxTQ1BSL3ky?= =?utf-8?B?N3oyTFJhTTFpNUwxUjg5YkI1aFhBdkx6cllTa2FuU0QvOWFZbE9JV0dzMnFw?= =?utf-8?B?L3JINSt0UWE0T0VRRjJEQ2V4TlhrUkhOZFZZQk5jSk9tTlo5MFBDaExQbkZE?= =?utf-8?B?YVl1NTFWSGNRWHVJVUhlR0RPQUZYdHJEaFVxTFd2WWJmcitQd0lyR29MbjhV?= =?utf-8?B?V1dBbHJTN3RkcjBBeVFDVXNNY0NBSVQyMExSdDRUK0FDbGpEYXp4cHl2c2lR?= =?utf-8?B?Qmc9PQ==?= X-OriginatorOrg: meta.com X-MS-Exchange-CrossTenant-Network-Message-Id: acd213bd-490f-4f28-ab19-08daf46de0f3 X-MS-Exchange-CrossTenant-AuthSource: SN6PR1501MB2064.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2023 07:23:19.0743 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4bBzN4+Rfp6BvU66c5emEez15USrxcL8hnV6edxWq8KlxbwT4ddLifEiMUWJmSdO X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR15MB4463 X-Proofpoint-GUID: cFkHBeCz7bvi0o9ne_oHIWP12vP3x3Ja X-Proofpoint-ORIG-GUID: cFkHBeCz7bvi0o9ne_oHIWP12vP3x3Ja X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-12_04,2023-01-11_03,2022-06-22_01 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 1/9/23 7:11 PM, Menglong Dong wrote: > On Tue, Jan 10, 2023 at 4:29 AM Yonghong Song wrote: >> >> >> >> On 1/9/23 1:42 AM, menglong8.dong@gmail.com wrote: >>> From: Menglong Dong >>> >>> The function name in kernel may be changed by the compiler. For example, >>> the function 'ip_rcv_core' can be compiled to 'ip_rcv_core.isra.0'. >>> >>> This kind optimization can happen in any kernel function. Therefor, we >>> should conside this case. >>> >>> If we failed to attach kprobe with a '-ENOENT', then we can lookup the >>> kallsyms and check if there is a similar function end with '.xxx', and >>> retry. >> >> This might produce incorrect result, so this approach won't work >> for all .isra.0 cases. When a function name is changed from >> to .isra., it is possible that compiler may have >> make some changes to the arguments, e.g., removing one argument, >> chaning a semantics of argument, etc. if bpf program still >> uses the original function signature, the bpf program may >> produce unexpected result. > > Oops, I wasn't aware of this part. Can we make this function disabled > by default and offer an option to users to enable it? Such as: > > bpf_object_adapt_sym(struct bpf_object *obj) > > In my case, kernel function rename is common, and I have to > check all functions and do such adaptation before attaching > my kprobe programs, which makes me can't use auto-attach. > > What's more, I haven't seen the arguments change so far, and > maybe it's not a common case? I don't have statistics, but it happens. In general, if you want to attach to a function like , but it has a variant .isra., you probably should check assembly code to ensure the parameter semantics not changed, and then you can attach to kprobe function .isra., which I assume current libbpf infrastructure should support it. After you investigate all these .isra. functions and confirm their argument semantics won't change, you could use kprobe multi to do attachment. > > (Please just ignore this reply if it doesn't work :/ ) > > Thanks! > Menglong Dong >> >>> >>> Signed-off-by: Menglong Dong >>> --- >>> tools/lib/bpf/libbpf.c | 37 ++++++++++++++++++++++++++++++++++++- >>> 1 file changed, 36 insertions(+), 1 deletion(-) >>> >>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c >>> index a5c67a3c93c5..fdfb1ca34ced 100644 >>> --- a/tools/lib/bpf/libbpf.c >>> +++ b/tools/lib/bpf/libbpf.c >>> @@ -10375,12 +10375,30 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, >>> return libbpf_err_ptr(err); >>> } >>> >>> +struct kprobe_resolve { >>> + char pattern[128]; >>> + char name[128]; >>> +}; >>> + >>> +static int kprobe_kallsyms_cb(unsigned long long sym_addr, char sym_type, >>> + const char *sym_name, void *ctx) >>> +{ >>> + struct kprobe_resolve *res = ctx; >>> + >>> + if (!glob_match(sym_name, res->pattern)) >>> + return 0; >>> + strcpy(res->name, sym_name); >>> + return 1; >>> +} >>> + >>> static int attach_kprobe(const struct bpf_program *prog, long cookie, struct bpf_link **link) >>> { >>> DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, opts); >>> + struct kprobe_resolve res = {}; >>> unsigned long offset = 0; >>> const char *func_name; >>> char *func; >>> + int err; >>> int n; >>> >>> *link = NULL; >>> @@ -10408,8 +10426,25 @@ static int attach_kprobe(const struct bpf_program *prog, long cookie, struct bpf >>> >>> opts.offset = offset; >>> *link = bpf_program__attach_kprobe_opts(prog, func, &opts); >>> + err = libbpf_get_error(*link); >>> + >>> + if (!err || err != -ENOENT) >>> + goto out; >>> + >>> + sprintf(res.pattern, "%s.*", func); >>> + if (!libbpf_kallsyms_parse(kprobe_kallsyms_cb, &res)) >>> + goto out; >>> + >>> + pr_warn("prog '%s': trying to create %s '%s+0x%zx' perf event instead\n", >>> + prog->name, opts.retprobe ? "kretprobe" : "kprobe", >>> + res.name, offset); >>> + >>> + *link = bpf_program__attach_kprobe_opts(prog, res.name, &opts); >>> + err = libbpf_get_error(*link); >>> + >>> +out: >>> free(func); >>> - return libbpf_get_error(*link); >>> + return err; >>> } >>> >>> static int attach_ksyscall(const struct bpf_program *prog, long cookie, struct bpf_link **link)