Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp727787pxb; Wed, 20 Jan 2021 20:15:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPzq0HR2DVR96a+TTynrbseNynZZKjslegUCVVxTxUTZUjFt3KQ/t67Ho7Q8kI/BsxU/wQ X-Received: by 2002:a17:906:4b44:: with SMTP id j4mr7789791ejv.23.1611202555712; Wed, 20 Jan 2021 20:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611202555; cv=none; d=google.com; s=arc-20160816; b=IrbzOTFM163LziauVKH7pFVE2VL3SCK5dxKfpd3jSqC0UrU+NPuAkRXq7GLvGWIfUi ZObxzpJG2eF3bos0UTth7qQA+3nQu+jZjaWK63PBVmwyxHfY/RXp2IVCqw+X2xRhfECp DYO0d27v6vKv3/+um90dY/NXfRsUm7TwgbfhHqfQvDVX0euUnvP2Q1Q1qmWyu3bSFe/d +zF7eDgpoPMnte/BIF1Yw7OWtO4pCgWBbFMk2jOLwkAO7QMQVYHNel6Wz78o8nHWsFR9 9g7c4wlY+dT9GJL1/yjPH0VEVL7tX1rrGA3n72R0sL5O7kNsjTKYDlt4SqSJ2AGk3yPT w29g== 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=qu3/Zdh2BNKct5hYooah1p1b6g8ncNuNlKHamiSiivA=; b=rqj6UFIeFUCfO/kxFwRtWbvyeul2/vf14vGLZixecdz0onuiURFgNS1k9eytbIyZzY S3U312qBclNmnWCPZETmTqgczQiCwjNBIUHav1FGu9TS4xymQq/rskkPIloWkZBkF/BC 1C3iOOr2gFtNWJyM+K0lG59us51YKpYVaEG7ebSddmjRpe+4UgWFJTHlGI6qOt+gFje/ fpJTN2iWouagFQwU3JFUZCtuxec2mCwZOJDT6A2z3e5QVSZqz7iDUf/sU7yuzTBDUT6O 3D0fj4WRL+wvRjNnDyomzrz8fUliuw2Jvc7ZSz+UWvtCElOGijqsNE0o+FYxi5f+P2AR OVIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="g1GDQ0/2"; 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 s13si1544203eds.57.2021.01.20.20.15.31; Wed, 20 Jan 2021 20:15:55 -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="g1GDQ0/2"; 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 S1726698AbhAUEO3 (ORCPT + 99 others); Wed, 20 Jan 2021 23:14:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727367AbhAUEMJ (ORCPT ); Wed, 20 Jan 2021 23:12:09 -0500 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40337C0613C1; Wed, 20 Jan 2021 20:11:29 -0800 (PST) Received: by mail-yb1-xb32.google.com with SMTP id y4so818758ybn.3; Wed, 20 Jan 2021 20:11:29 -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=qu3/Zdh2BNKct5hYooah1p1b6g8ncNuNlKHamiSiivA=; b=g1GDQ0/2al2sF4aWAkymdbAOYl7xXJT9cS080xkUl2BLzz4WAflrgOdR9Ojm2yyihp +/2j5bPtR3kI6MDbS1UBXWQknA+PjJxtmtSL0IrGqd8jjbtLYqLua7bgJFLlSD/5NdSO ob+0I1vujlrPSvbyDDsM5YGUZkEUPmmu+eFeG4nN8H9gRtKvLlu3a314psxwaJGExRKt El2oKC32NDPolLz8s+n/hgAlQAsVgZv7Dn2joEGFXA648OXggdgKoOHq9N3oyK8ph/o9 oYQl10t7H6B3aiXNX07rmuS/22JNKBdl0g35Hm00uC8tJyXIyT70jh3XfU+kvW0g0XF1 ZOYg== 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=qu3/Zdh2BNKct5hYooah1p1b6g8ncNuNlKHamiSiivA=; b=c4wHGn0x3aLzt/mXOFGHJFkVOo7Xz42pXlhy7uTOsoZQNiIg9u3z+T2LoJSpcD7h8d MTtRX21jXnsR7ygGMuXs0lTmChodWWRCriBK1v6SD2PudONPL5Yl2rqiBu9TzODzLb5E x+YzAwcCpQovQ6g6tXBx1VE+4SWWvICZmUpbH95Ycn6R3fhhmXcZKv866h6yyBkMnE0c et73H2TnHnqdv39wCR8+o2oenRqhK4mP2PFNr5cZ+Y8NpY+WwmJ9ORe0Dw+JG9GMFqTE 8kSh0uH36gSLMDjzCWp3fYuWNHZm0W+c59BLrxiwahI9ksV/v0ZqoYVTXdIqAMrqQBfI jwvg== X-Gm-Message-State: AOAM533hRfHNo2+XYl5pqEl91qEuAlcRWNp9aJ8N5eCQBoWQQVVQuECI KhuXVv4vb2FA49o5AJwvXQ5hCsXDPPcgIMlVjnc= X-Received: by 2002:a25:854a:: with SMTP id f10mr16748389ybn.510.1611202288424; Wed, 20 Jan 2021 20:11:28 -0800 (PST) MIME-Version: 1.0 References: <1610921764-7526-1-git-send-email-alan.maguire@oracle.com> <1610921764-7526-2-git-send-email-alan.maguire@oracle.com> In-Reply-To: <1610921764-7526-2-git-send-email-alan.maguire@oracle.com> From: Andrii Nakryiko Date: Wed, 20 Jan 2021 20:11:17 -0800 Message-ID: Subject: Re: [PATCH v2 bpf-next 1/4] libbpf: add btf_has_size() and btf_int() inlines To: Alan Maguire Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , morbo@google.com, Shuah Khan , bpf , Networking , "open list:KERNEL SELFTEST FRAMEWORK" , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 17, 2021 at 2:22 PM Alan Maguire wrote: > > BTF type data dumping will use them in later patches, and they > are useful generally when handling BTF data. > > Signed-off-by: Alan Maguire > --- > tools/lib/bpf/btf.h | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h > index 1237bcd..0c48f2e 100644 > --- a/tools/lib/bpf/btf.h > +++ b/tools/lib/bpf/btf.h > @@ -294,6 +294,20 @@ static inline bool btf_is_datasec(const struct btf_type *t) > return btf_kind(t) == BTF_KIND_DATASEC; > } > > +static inline bool btf_has_size(const struct btf_type *t) > +{ > + switch (BTF_INFO_KIND(t->info)) { > + case BTF_KIND_INT: > + case BTF_KIND_STRUCT: > + case BTF_KIND_UNION: > + case BTF_KIND_ENUM: > + case BTF_KIND_DATASEC: > + return true; > + default: > + return false; > + } > +} it's not clear what "has_size" means, actually. E.g., array type definitely has size, it's not just as readily available. And you are actually misusing this in your algorithm, I'll point it out in the respective patch. Please remove this, or if absolutely necessary move into btf_dump.c as an inner static function. > + > static inline __u8 btf_int_encoding(const struct btf_type *t) > { > return BTF_INT_ENCODING(*(__u32 *)(t + 1)); > @@ -309,6 +323,11 @@ static inline __u8 btf_int_bits(const struct btf_type *t) > return BTF_INT_BITS(*(__u32 *)(t + 1)); > } > > +static inline __u32 btf_int(const struct btf_type *t) > +{ > + return *(__u32 *)(t + 1); > +} > + there is btf_int_encoding(), btf_ind_offset() and btf_int_bits() that properly decompose what btf_int() above returns. I'm not convinced btf_int() has to be exposed as a public API. > static inline struct btf_array *btf_array(const struct btf_type *t) > { > return (struct btf_array *)(t + 1); > -- > 1.8.3.1 >