Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1789277pxv; Fri, 16 Jul 2021 18:20:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBTz5VZPJVvdkjCOX4pn/0BMdJqbdyTRXXig4CLBE4rXMVFbj5JrF9CUZLUP2lnvwiLvxw X-Received: by 2002:aa7:cc92:: with SMTP id p18mr3011393edt.365.1626484854264; Fri, 16 Jul 2021 18:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626484854; cv=none; d=google.com; s=arc-20160816; b=n1/GwgKCnyyID/SRvAiQg4l8QJxzSfbyzECnl9qUYK5JBPlTc+1/G9lmeDpk5H+2eO B43oD+WaEDmP+1LeTVxBM86kYVloLCxdmiS4xtWg8NxCTb26XxW7WbRVJ97BY8BvIdVp 6wHY5HUu5n2LWI4R4zk27F32Ku0FVU6l4cy+sSCAE1I01EWlS/E79Oc7yM40k3Rg9RLA 9n8wpLbplJ2T6KZfkVSMgW7+qeVHmd/DDddME8S4b2RgK422xQnfURPUKqjGq+xqFkBx ssM9Z28aqA+CwC78PeyMU6Aj6/+oRqb3TPdFyxBMdfqRxZCw/jhyfLsvW1P2umQvzAfV Im1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=kuUsEXgkn7YSjfIUDY/HF2klbjPEaFzSKc9FiEzyz98=; b=s2Hzb+XtSxqcVWg4o0ldcU2prsGSpFVh7heJcVWhyUSv6oi6AlY1kCBGuenGRfVEW8 pqI4XCH6npTQpI0lSUh4/4S6capPCZ/RrNkkI6ZlxwNk58BBa2YmiMoEySaTXlfp2xJm b2DbwGccgPWX8esLeGwi81nsa6+G0DEG54xYv1HdbAA0XrsDNfUilCqxSF3QaM7yoEnO bgOkixJy3vEwflAMztLUGSj+PIpBUJZQcct4lp3OCy7FQCt2iJ6Ze+lfj7kB7BYNZyZc RmjzxEA9mj/xAxVBuqu1gnDvVKOguZq/Gg/dpiN9yNrOjoSwQfqyNNopMryW5Aa7/rkI 985g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si12620412edu.127.2021.07.16.18.20.29; Fri, 16 Jul 2021 18:20:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232457AbhGQBSt (ORCPT + 99 others); Fri, 16 Jul 2021 21:18:49 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:43251 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbhGQBSt (ORCPT ); Fri, 16 Jul 2021 21:18:49 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=chengshuyi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0Ug.os52_1626484550; Received: from B-39YZML7H-2200.local(mailfrom:chengshuyi@linux.alibaba.com fp:SMTPD_---0Ug.os52_1626484550) by smtp.aliyun-inc.com(127.0.0.1); Sat, 17 Jul 2021 09:15:50 +0800 Subject: Re: [PATCH bpf-next v4 1/3] libbpf: Introduce 'btf_custom_path' to 'bpf_obj_open_opts' To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , Networking , bpf , open list , kernel-janitors@vger.kernel.org References: <1626180159-112996-1-git-send-email-chengshuyi@linux.alibaba.com> <1626180159-112996-2-git-send-email-chengshuyi@linux.alibaba.com> From: Shuyi Cheng Message-ID: <0fa3b7f1-7928-eff9-1644-df3384171bcd@linux.alibaba.com> Date: Sat, 17 Jul 2021 09:15:50 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/16/21 12:51 PM, Andrii Nakryiko wrote: > On Tue, Jul 13, 2021 at 5:43 AM Shuyi Cheng > wrote: >> >> btf_custom_path allows developers to load custom BTF, and subsequent >> CO-RE will use custom BTF for relocation. >> >> Learn from Andrii's comments in [0], add the btf_custom_path parameter >> to bpf_obj_open_opts, you can directly use the skeleton's >> _bpf__open_opts function to pass in the btf_custom_path >> parameter. >> >> Prior to this, there was also a developer who provided a patch with >> similar functions. It is a pity that the follow-up did not continue to >> advance. See [1]. >> >> [0]https://lore.kernel.org/bpf/CAEf4BzbJZLjNoiK8_VfeVg_Vrg=9iYFv+po-38SMe=UzwDKJ=Q@mail.gmail.com/#t >> [1]https://yhbt.net/lore/all/CAEf4Bzbgw49w2PtowsrzKQNcxD4fZRE6AKByX-5-dMo-+oWHHA@mail.gmail.com/ >> >> Signed-off-by: Shuyi Cheng >> --- >> tools/lib/bpf/libbpf.c | 36 ++++++++++++++++++++++++++++++------ >> tools/lib/bpf/libbpf.h | 9 ++++++++- >> 2 files changed, 38 insertions(+), 7 deletions(-) >> >> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c >> index 1e04ce7..6e11a7b 100644 >> --- a/tools/lib/bpf/libbpf.c >> +++ b/tools/lib/bpf/libbpf.c >> @@ -498,6 +498,13 @@ struct bpf_object { >> * it at load time. >> */ >> struct btf *btf_vmlinux; >> + /* Path to the custom BTF to be used for BPF CO-RE relocations. >> + * This custom BTF completely replaces the use of vmlinux BTF >> + * for the purpose of CO-RE relocations. >> + * NOTE: any other BPF feature (e.g., fentry/fexit programs, >> + * struct_ops, etc) will need actual kernel BTF at /sys/kernel/btf/vmlinux. >> + */ > > this comment completely duplicates the one from bpf_object_open_opts, > I'll remove or shorten it > >> + char *btf_custom_path; >> /* vmlinux BTF override for CO-RE relocations */ >> struct btf *btf_vmlinux_override; >> /* Lazily initialized kernel module BTFs */ >> @@ -2645,10 +2652,6 @@ static bool obj_needs_vmlinux_btf(const struct bpf_object *obj) >> struct bpf_program *prog; >> int i; >> >> - /* CO-RE relocations need kernel BTF */ >> - if (obj->btf_ext && obj->btf_ext->core_relo_info.len) >> - return true; >> - >> /* Support for typed ksyms needs kernel BTF */ >> for (i = 0; i < obj->nr_extern; i++) { >> const struct extern_desc *ext; >> @@ -2665,6 +2668,13 @@ static bool obj_needs_vmlinux_btf(const struct bpf_object *obj) >> return true; >> } >> >> + /* CO-RE relocations need kernel BTF, only when btf_custom_path >> + * is not specified >> + */ >> + if (obj->btf_ext && obj->btf_ext->core_relo_info.len >> + && !obj->btf_custom_path) >> + return true; > > not sure why you moved it, I'll move it back to minimize code churn You're right. ???? regards, Shuyi > >> + >> return false; >> } >> > > [...] >