Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1709178pxb; Fri, 6 Nov 2020 17:53:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPm8M9cDCQrZt94w6P6dBQ7jQCXot6JsCSmC0qh6XborTXNvYGRn2ZPlpSGu24v3/hoVMr X-Received: by 2002:aa7:c5d0:: with SMTP id h16mr5173140eds.7.1604714039740; Fri, 06 Nov 2020 17:53:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604714039; cv=none; d=google.com; s=arc-20160816; b=kiE7agHLRHKtJED+vWTniRu/cp9Hl8JC8HGKO9jFZ0yZdLS57J5OnQyq6XRFJNvyOM CKsUzyZuVSHRIqRORXLGn2vO677PXsjiO9RPfde88t/huxe3cuvYn8wntJzk2EIUj/2w sc4GfYC+fP613pTRN/6TOcUxYCYCBBXm7PC9x0VONfvshKME+OhjEC3lpxHJA1OLd5ml jVWdNpozINSyOgRv3uyrQJDsA6qkuCKJouoXoEgvhnM2qd82zW1bxTQQHzivRrDYN3PT 8abJFJ5THazdrfzxEt9rbDrDCRFjPrzVUx7RcokBSCMHpxbtrlakXe4BiN8c38Nt3xv9 uYVg== 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=htDTYjHxkl8pJF7YHCGD1ZPutKHgCLrJs1VPdouellw=; b=HA5JxkKa5kgSq6CxlMq4145kVxz0OfAD3IcUvZmK7yFK925Jmh8rQ3xFlwnZtCNtzn LZH0uJYA3ExXWBGqXwrZzlWwxPT3MIQ0Yr5TmDLMo58JGlx/oK0ZzSe+aKEYGsOg7Pb/ tSe8ARGscW0AP64X4iAabkHF1MhKDufA20kcrxD3kTo4kXaLawsCzWu+hRksy2b3Zdlk 5uEznSbduHX7CuAagyzTUBSSv+s0MNSugqd9iM3bhuQaZyhXLdFiUSEXYabRKd5hNvhK Qkbf8A50XCny6ebhG5loJE15Tzw+vYrmuth+FaG9Z4RJ5xWIIPuD4zTxwALaVy37Xnl4 yYwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QZLDbSvi; 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 b17si2525896edw.47.2020.11.06.17.53.34; Fri, 06 Nov 2020 17:53:59 -0800 (PST) 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=QZLDbSvi; 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 S1728372AbgKGBwI (ORCPT + 99 others); Fri, 6 Nov 2020 20:52:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727129AbgKGBwI (ORCPT ); Fri, 6 Nov 2020 20:52:08 -0500 Received: from mail-yb1-xb42.google.com (mail-yb1-xb42.google.com [IPv6:2607:f8b0:4864:20::b42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5AABC0613CF; Fri, 6 Nov 2020 17:52:07 -0800 (PST) Received: by mail-yb1-xb42.google.com with SMTP id m188so2808368ybf.2; Fri, 06 Nov 2020 17:52:07 -0800 (PST) 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=htDTYjHxkl8pJF7YHCGD1ZPutKHgCLrJs1VPdouellw=; b=QZLDbSviyGyu7BFxBlQygO3Ug4vsO3xn8BJYpTidIg3bS/hLq8RkUwW/IQlmHTzul0 QLzc3K+A5/RmTJksI3yCs6/i51OAcUMb1Nwydu5kGwOAIcfuQHooCvbIp7msi92lOIbP WqBoGCqpdMnpHPLPXr2YOexIyctT0YLlBZ4a8m2NWcBAKfvAR42D74TJTps0n30ht9tN JPmSLCTMVo8AvrYCOkTsQ6kBR5y+8GU1S/vpJgNKvqKSg6tG9WlO6SsM5IUBgF2/PeDE NKbIWMrL9sUSzC+MXS8v4Wo6RsCVyU7/QIKruiKeM/4amnoN5dYa2+zpLf1vsa7kZeD7 9CdQ== 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=htDTYjHxkl8pJF7YHCGD1ZPutKHgCLrJs1VPdouellw=; b=RzJweUw3k0I/8qTEQZWEdqvdMD88tcTX/bGQmZurmN6Gyn2xiGonykOluPzuUlZDgI az/tqy/M0of7JGrc/MkEkDaiUYnmPdLHfFFbof/DqC85Di3ZCbBajWclSyIStFbkaBcT Xcsu/GNOAzYwkFeTLfnCs/pcTMZ5/XlWzuHJxKcvLTGLSzbo6mertoJ/6aj12/oFVkvd P6wLcAL7QslMbGiIxJLjJEDmaW5IQPL32hACCJmJGbcLbhqMQK9/rd2R/jgG8Ajjex1B qpXbNSeLWQ4lgP0D2yfUDYCuEkWvA6cL6XRvm58y65kxZGZJkUxVxTDzjvHirW/Vdf2X 5z1w== X-Gm-Message-State: AOAM531B4Chc3pGq2h/utDSM7STdG85B4OoZAyGEXSZpHVPHJS0USzVj 32P7JV7cYGyoZiHiVorG0+D2JxB9XpdA8rOpDow= X-Received: by 2002:a25:c7c6:: with SMTP id w189mr6951356ybe.403.1604713926926; Fri, 06 Nov 2020 17:52:06 -0800 (PST) MIME-Version: 1.0 References: <20201106230228.2202-1-andrii@kernel.org> <20201106230228.2202-2-andrii@kernel.org> <712CED9D-91E3-4CF1-AAFC-3E970582D06D@fb.com> In-Reply-To: <712CED9D-91E3-4CF1-AAFC-3E970582D06D@fb.com> From: Andrii Nakryiko Date: Fri, 6 Nov 2020 17:51:56 -0800 Message-ID: Subject: Re: [PATCH v2 bpf-next 1/5] bpf: add in-kernel split BTF support To: Song Liu Cc: Andrii Nakryiko , bpf , Networking , Alexei Starovoitov , Daniel Borkmann , Kernel Team , open list , "rafael@kernel.org" , "jeyu@kernel.org" , Arnaldo Carvalho de Melo , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 6, 2020 at 5:28 PM Song Liu wrote: > > > > > On Nov 6, 2020, at 3:02 PM, Andrii Nakryiko wrote: > > > > Adjust in-kernel BTF implementation to support a split BTF mode of operation. > > Changes are mostly mirroring libbpf split BTF changes, with the exception of > > start_id being 0 for in-kernel implementation due to simpler read-only mode. > > > > Otherwise, for split BTF logic, most of the logic of jumping to base BTF, > > where necessary, is encapsulated in few helper functions. Type numbering and > > string offset in a split BTF are logically continuing where base BTF ends, so > > most of the high-level logic is kept without changes. > > > > Type verification and size resolution is only doing an added resolution of new > > split BTF types and relies on already cached size and type resolution results > > in the base BTF. > > > > Signed-off-by: Andrii Nakryiko > > [...] > > > > > @@ -600,8 +618,15 @@ static const struct btf_kind_operations *btf_type_ops(const struct btf_type *t) > > > > static bool btf_name_offset_valid(const struct btf *btf, u32 offset) > > { > > - return BTF_STR_OFFSET_VALID(offset) && > > - offset < btf->hdr.str_len; > > + if (!BTF_STR_OFFSET_VALID(offset)) > > + return false; > > +again: > > + if (offset < btf->start_str_off) { > > + btf = btf->base_btf; > > + goto again; > > Can we do a while loop instead of "goto again;"? yep, not sure why I went with goto... while (offset < btf->start_str_off) btf = btf->base_btf; Shorter. > > > + } > > + offset -= btf->start_str_off; > > + return offset < btf->hdr.str_len; > > } > > > > static bool __btf_name_char_ok(char c, bool first, bool dot_ok) > > @@ -615,10 +640,25 @@ static bool __btf_name_char_ok(char c, bool first, bool dot_ok) > > return true; > > } > > > > +static const char *btf_str_by_offset(const struct btf *btf, u32 offset) > > +{ > > +again: > > + if (offset < btf->start_str_off) { > > + btf = btf->base_btf; > > + goto again; > > + } > > Maybe add a btf_find_base_btf(btf, offset) helper for this logic? No strong feelings about this, but given it's a two-line loop might not be worth it. I'd also need a pretty verbose btf_find_base_btf_for_str_offset() and btf_find_base_btf_for_type_id(). I feel like loop might be less distracting actually. > > > + > > + offset -= btf->start_str_off; > > + if (offset < btf->hdr.str_len) > > + return &btf->strings[offset]; > > + > > + return NULL; > > +} > > + > > [...] > > > } > > > > const char *btf_name_by_offset(const struct btf *btf, u32 offset) > > { > > - if (offset < btf->hdr.str_len) > > - return &btf->strings[offset]; > > - > > - return NULL; > > + return btf_str_by_offset(btf, offset); > > } > > IIUC, btf_str_by_offset() and btf_name_by_offset() are identical. Can we > just keep btf_name_by_offset()? btf_str_by_offset() is static, so should be inlinable, while btf_name_by_offset() is a global function, I was worrying about regressing performance for __btf_name_valid() and __btf_name_by_offset(). Premature optimization you think? > > > > > const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id) > > { > > - if (type_id > btf->nr_types) > > - return NULL; > > +again: > > + if (type_id < btf->start_id) { > > + btf = btf->base_btf; > > + goto again; > > + } > > ditto, goto again.. > > [...] > >