Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp979651pxv; Thu, 15 Jul 2021 21:52:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA9hzblCVReRr4hnMI+xLOOn9xDJ9V0FlGvpMXSHp48/0kg5W/pnLbGp7Qyr847zJy1+55 X-Received: by 2002:a05:6638:1316:: with SMTP id r22mr7313500jad.89.1626411171549; Thu, 15 Jul 2021 21:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626411171; cv=none; d=google.com; s=arc-20160816; b=hSrF8TL8ihYJ2KLRlVNAtJ5zhrlAjzo7q4fSJainCtNHvixRUnoTyiPQ1jXQo/yP6B RCgCDQ8f8VauiP5B9cxr+vYrMhXKLd1tI0oIDQSgxkAAePaiwLZHNF4Riybs7N2ta7RQ +/TztvFuKZX1AeMSipJqztpN5pxqsYGwt+odncEl1On6oqPdHklvc9L67Qbs8VAzlTdK IDBrlLMRFqKdOViqpip+YkXWlumAUwRummDMPX6yCAF5G1gHYsSI9SjsNSdnWTN26Ytf /fG8cjsyfFKHV5TP5RQ7KEKdT9LpnF3keN61njgm27viY09T1rs7SV9xTZjEe9s2+u5e 3YtQ== 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=zZOKpKFYgjHW50PMmYKSx4ZCJG/+r41CwlwkRApL2oo=; b=tXEYoM7FBURzGprvyEThjoTO2l6mnUmuVuLS0SMiiEBNGeTdkLslinJt7lVSqdNEla ET5uhI2iwrmKvSmBWh7MGAOaV7syCDEc3IKd1iSendnSMIaAnp3VYTL8KPI7Q5xqC6Vw w41t0JFVMWvm0222eYS1fu8RBHZs1bE3kETIq+ZnKoUF3Yv6I0mcked3fzpRva9Rxb7x OWGJvCngGo++VrRiJ1kHSO1D7kYwiNkayQMt9+cf9/IDlWIzzthLEtJ3BElez3VrhWnF r300mzbuY3OqvxjOt5mt2zwF87OZsxU/G7zoFnmQda4ZTbJNYy8P79yHz4nILfO4/lvU kHnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Pdpt1XTD; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si10106325jad.101.2021.07.15.21.52.39; Thu, 15 Jul 2021 21:52:51 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Pdpt1XTD; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233986AbhGPEyp (ORCPT + 99 others); Fri, 16 Jul 2021 00:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbhGPEyp (ORCPT ); Fri, 16 Jul 2021 00:54:45 -0400 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D27FC06175F; Thu, 15 Jul 2021 21:51:50 -0700 (PDT) Received: by mail-yb1-xb36.google.com with SMTP id g5so12810795ybu.10; Thu, 15 Jul 2021 21:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zZOKpKFYgjHW50PMmYKSx4ZCJG/+r41CwlwkRApL2oo=; b=Pdpt1XTD7FI9phIjoTD8KQA1HKCoUQcOqXw9wesHD5Ov9rlqEC4jBLJCAH7mzPV1d+ L3DYVhebtRw7aLMHa/J9HyVzxPxuPCnOPugAmM+6Dd408gr0lwiKeIbaJBJBap1ki5wz 2+dThjnWu0ac8ydA8gnL98v7c8PdbtTm+ZBsDRCvDatHvJ4sCkvwEWFe7klgbtsNxrdA S/k5YRT8wXf/ilraAYurpChCwySWXJ5E0npfvu+fABycIwVlsK7Z9A3r5PSWZLhIe3oy 48HQ+uDxOaQF9qz6OOAHExeRNqgEcpzexbpGvp7nfYSQ+KlsLn1TgDKCs9UxcY/XGhKe u/QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zZOKpKFYgjHW50PMmYKSx4ZCJG/+r41CwlwkRApL2oo=; b=kKPKWQYnJC8Iy4PTPH625sJwqBLnjtl4H8021+QuwwRqe4vFgomhMd85cBGNy26xNR vRN7FVzFcFTr1zzJsinw42uaFg6ldAwmRNNlouKA//iKQv68Td1qXhL0L8AuIUGRloNO BcmgoCw7Zq3sNgKrAdqwiDOMR2+KovsbH0OiG92CbKKxFJON6S7CxUCY+Gxf3FtQq5X+ kY54159O2LjUwWrmas5nWnVHLRrp58sFCSYfNjQXsh3uw0L20ckeGqzKqfxLgBlB1L6f zByFGlrhKS5UlC4wI2S6Cb/WSPQrGz3yCjs6YCAfnFLMdfkUE0MuraeNJKnwHT3vya4R YY7A== X-Gm-Message-State: AOAM531i8JajTmm3MCYSqno0FQrtOMB7ehvvJ9cD8FNqMcqdTTAhXbGc IgzwuKdF+VAb4hRdqM/aNBff1VJ/+8fnsHleSyE= X-Received: by 2002:a25:d349:: with SMTP id e70mr10203729ybf.510.1626411109339; Thu, 15 Jul 2021 21:51:49 -0700 (PDT) MIME-Version: 1.0 References: <1626180159-112996-1-git-send-email-chengshuyi@linux.alibaba.com> <1626180159-112996-2-git-send-email-chengshuyi@linux.alibaba.com> In-Reply-To: <1626180159-112996-2-git-send-email-chengshuyi@linux.alibaba.com> From: Andrii Nakryiko Date: Thu, 15 Jul 2021 21:51:38 -0700 Message-ID: Subject: Re: [PATCH bpf-next v4 1/3] libbpf: Introduce 'btf_custom_path' to 'bpf_obj_open_opts' To: Shuyi Cheng 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > + > return false; > } > [...]