From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FD67C32771 for ; Fri, 24 Jan 2020 14:12:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 410822075D for ; Fri, 24 Jan 2020 14:12:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="iJ2fU2hU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390180AbgAXOML (ORCPT ); Fri, 24 Jan 2020 09:12:11 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35105 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387508AbgAXOML (ORCPT ); Fri, 24 Jan 2020 09:12:11 -0500 Received: by mail-pf1-f194.google.com with SMTP id i23so1177180pfo.2 for ; Fri, 24 Jan 2020 06:12:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Iz5cHqMUZemh4vAyieC4PCm90mjuvS7GOLpZDZYwVvE=; b=iJ2fU2hUfwnRDmxd/eXMmRa2aMXc0i2MJXp7+HH9Tf0DRiVk3U9TSlE4p6wTcXeGQv 50oTElkkEj0ajwNnarMd9pDPixfviwyCRyGnKD0QN/RriohADXzI+qbpNolRcH/dRy8y MlxvbyHbViJJeVlVsAJt7in3W1+a52g6VGY3Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Iz5cHqMUZemh4vAyieC4PCm90mjuvS7GOLpZDZYwVvE=; b=b9Rt6K28nP/HfXStLS/Jw6xDC1ZON4b13xBogMwwZptDfEEs7vmLomernyyVxJpFfM I3WL8PIQQ63WfuKaicdcdX3SuGWzNfJxnP0va16lZkZcl+JcT6UfDQ3CJBXuIKgwDMUO Gq3oYRTzBzIWzEcclMpW4MyUj+puPeIp2uSTfuY+Tmq8/NKTFT5tifmrEExXIK30aTNH XsVaylDGPquFZWcsjTLMCf0kFl1ElYIHMkmSRrLwUXOM9oV/xtDqGVYY59PWvKJjLa+R 29Cgl/EYaij4hW56/k8ekrBsOxVfheyl0cyPO3Ou+qFLsZo8ngPo7iWgGVR7/Zanj5N+ 1ZWA== X-Gm-Message-State: APjAAAX44cM5ajX4uqyp+0a4ZluOFcRt2DabNKbPKd0gJqyPiL1dC6C4 1g8rL/QchvBYOTR4pHxwTukOuA== X-Google-Smtp-Source: APXvYqyEY68xNjBYfjXdbh+1/z6XOSVIUgDGnsumwmzifqvXVisLTjDtm3Q6i/HD+sE7qbfNuJmhVg== X-Received: by 2002:a63:cb06:: with SMTP id p6mr4355321pgg.236.1579875130290; Fri, 24 Jan 2020 06:12:10 -0800 (PST) Received: from chromium.org ([2601:647:4903:8020:88e3:d812:557:e2e5]) by smtp.gmail.com with ESMTPSA id u20sm6599646pgf.29.2020.01.24.06.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 06:12:09 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Fri, 24 Jan 2020 06:12:03 -0800 To: Andrii Nakryiko Cc: open list , bpf , linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Thomas Garnier , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Thomas Garnier , Michael Halcrow , Paul Turner , Brendan Gregg , Jann Horn , Matthew Garrett , Christian Brauner , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Florent Revest , Brendan Jackman , Martin KaFai Lau , Song Liu , Yonghong Song , "Serge E. Hallyn" , Mauro Carvalho Chehab , "David S. Miller" , Greg Kroah-Hartman , Nicolas Ferre , Stanislav Fomichev , Quentin Monnet , Andrey Ignatov , Joe Stringer Subject: Re: [PATCH bpf-next v3 01/10] bpf: btf: Add btf_type_by_name_kind Message-ID: <20200124141203.GA21334@chromium.org> References: <20200123152440.28956-1-kpsingh@chromium.org> <20200123152440.28956-2-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23-Jan 12:06, Andrii Nakryiko wrote: > On Thu, Jan 23, 2020 at 7:25 AM KP Singh wrote: > > > > From: KP Singh > > > > - The LSM code does the combination of btf_find_by_name_kind and > > btf_type_by_id a couple of times to figure out the BTF type for > > security_hook_heads and security_list_options. > > - Add an extern for btf_vmlinux in btf.h > > > > Signed-off-by: KP Singh > > Reviewed-by: Brendan Jackman > > Reviewed-by: Florent Revest > > Reviewed-by: Thomas Garnier > > --- > > include/linux/btf.h | 3 +++ > > kernel/bpf/btf.c | 12 ++++++++++++ > > 2 files changed, 15 insertions(+) > > > > diff --git a/include/linux/btf.h b/include/linux/btf.h > > index 5c1ea99b480f..d4e859f90a39 100644 > > --- a/include/linux/btf.h > > +++ b/include/linux/btf.h > > @@ -15,6 +15,7 @@ struct btf_type; > > union bpf_attr; > > > > extern const struct file_operations btf_fops; > > +extern struct btf *btf_vmlinux; > > > > void btf_put(struct btf *btf); > > int btf_new_fd(const union bpf_attr *attr); > > @@ -66,6 +67,8 @@ const struct btf_type * > > btf_resolve_size(const struct btf *btf, const struct btf_type *type, > > u32 *type_size, const struct btf_type **elem_type, > > u32 *total_nelems); > > +const struct btf_type *btf_type_by_name_kind( > > + struct btf *btf, const char *name, u8 kind); > > > > #define for_each_member(i, struct_type, member) \ > > for (i = 0, member = btf_type_member(struct_type); \ > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > > index 32963b6d5a9c..ea53c16802cb 100644 > > --- a/kernel/bpf/btf.c > > +++ b/kernel/bpf/btf.c > > @@ -441,6 +441,18 @@ const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf, > > return NULL; > > } > > > > +const struct btf_type *btf_type_by_name_kind( > > + struct btf *btf, const char *name, u8 kind) > > +{ > > + s32 type_id; > > + > > + type_id = btf_find_by_name_kind(btf, name, kind); > > + if (type_id < 0) > > + return ERR_PTR(type_id); > > + > > + return btf_type_by_id(btf, type_id); > > +} > > + > > is it worth having this as a separate global function? If > btf_find_by_name_kind returns valid ID, then you don't really need to > check btf_type_by_id result, it is always going to be valid. So the > pattern becomes: Yeah you're right. We went from using this a few times in separate functions to 2 times in the same function (based on the changes in v2 -> v3) I will drop this from the next revision. > type_id = btf_find_by_name_kind(btf, name, kind); > if (type_id < 0) > goto handle_error; > t = btf_type_by_id(btf, type_id); > /* now just use t */ > > which is not much more verbose than: > > t = btf_type_by_name_kind(btf, name, kind); > if (IS_ERR(t)) > goto handle_error > /* now use t */ > Agreed. - KP > > > /* Types that act only as a source, not sink or intermediate > > * type when resolving. > > */ > > -- > > 2.20.1 > >