Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp624420ybl; Fri, 24 Jan 2020 06:38:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzQw0nsqBKBVB+HvlKh4O6T8p5972ybc/AODr7GUJSN4ODzuLdT4yaxTTU1uU+2+6P+pNr6 X-Received: by 2002:a05:6830:13d3:: with SMTP id e19mr2933641otq.135.1579876703543; Fri, 24 Jan 2020 06:38:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579876703; cv=none; d=google.com; s=arc-20160816; b=hkEZEooTFMEliHYxy+AOoDrcEYa5OMaWN9zhXjdNj5iD136uspK3dnFpJymYI2nrrG d3L93VdMUY6g0Va37WOSL4qdBlnoJHBJoxj9o6saMuLtegKiXeWfeKWeVTIX3Roayqdj gtdOb3JO3f0dOY33qeGJtfiGoUsK7jXITC0BV3smnSGZW6pW6Iv0ZoKpu1HXVjE/SeJE pL2ANuFe3bUc/dbIRQAfsoDG1S+fD3nvR7DQMF5U4E6NQTaulpCMS87XQMYSJ0TsThzL HWV7NPlnaD7OUTTqzLrDgH/1vp6G7YUWgTsTCiY8x5SK0vIWtsPu4jXMXRfenYDFKuxS DVvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=Iz5cHqMUZemh4vAyieC4PCm90mjuvS7GOLpZDZYwVvE=; b=VOJBjtTsNRofnXHvUke5AZxnfukbeMNBEe/O28kfPemdW8MCL83G08AKUvLl8N22Qa E8KNEFhYXPFE8VuoH0ZxVLcBOCIIx0uuq4AqCLVhXSXS5ZusTDvf1yJhmFTSaqs21qrJ tyxD+KnMB389cBjTDw3nJjrCt08xhqxIgyxOkJ16wbUE274m3XfKf6MEAw8L6NQ4E8p7 Nkm2ETcbo6lpu/O9gImiyDcuKg2dEYB/jF+v0hOToVznGrzlinzTmWftn2aJwOml18GE jo6MI7J9sQy0AAI4YZDMBZkXMhVK64lvYfLKkNwNHdQc1KYTPLI63ky6RK4+M79h1JMs jKbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iJ2fU2hU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si1653945ota.322.2020.01.24.06.38.10; Fri, 24 Jan 2020 06:38:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iJ2fU2hU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390173AbgAXOML (ORCPT + 99 others); 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-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 > >