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=-7.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 DA05FC433E0 for ; Wed, 5 Aug 2020 21:31:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9ED2222CA1 for ; Wed, 5 Aug 2020 21:31:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I269qYgZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725648AbgHEVbu (ORCPT ); Wed, 5 Aug 2020 17:31:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:28134 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725920AbgHEVbt (ORCPT ); Wed, 5 Aug 2020 17:31:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596663107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hrYzbsbkUJqRh8UB3Rf9hLYq/J78NU+rtLB4ERSzskA=; b=I269qYgZ7H4yHHT6/Z0FHfpJv3Aj92460YmW9mNhBxP+ttDw4frD/ZBH4do/ph1yrpGu7o PwqAPouGmRvLGhv6JDtHBF01mDNTCtXuhedwcSEZk39fZeccRww8P13CPgLGdEciluSse8 IzStBIe+htOMvSzV6nVJBHPlgrqPqy4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-85-xGP-JgLpOQ-AfmlXGAhZIA-1; Wed, 05 Aug 2020 17:31:43 -0400 X-MC-Unique: xGP-JgLpOQ-AfmlXGAhZIA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D420800685; Wed, 5 Aug 2020 21:31:41 +0000 (UTC) Received: from krava (unknown [10.40.192.11]) by smtp.corp.redhat.com (Postfix) with SMTP id 9340487A41; Wed, 5 Aug 2020 21:31:37 +0000 (UTC) Date: Wed, 5 Aug 2020 23:31:36 +0200 From: Jiri Olsa To: Andrii Nakryiko Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Networking , bpf , Song Liu , Yonghong Song , Martin KaFai Lau , David Miller , John Fastabend , Wenbo Zhang , KP Singh , Brendan Gregg , Florent Revest , Al Viro Subject: Re: [PATCH v9 bpf-next 08/14] bpf: Add btf_struct_ids_match function Message-ID: <20200805213136.GG319954@krava> References: <20200801170322.75218-1-jolsa@kernel.org> <20200801170322.75218-9-jolsa@kernel.org> <20200805175651.GC319954@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200805175651.GC319954@krava> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Wed, Aug 05, 2020 at 07:56:51PM +0200, Jiri Olsa wrote: > On Tue, Aug 04, 2020 at 11:27:55PM -0700, Andrii Nakryiko wrote: > > SNIP > > > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > > > index 7bacc2f56061..ba05b15ad599 100644 > > > --- a/kernel/bpf/btf.c > > > +++ b/kernel/bpf/btf.c > > > @@ -4160,6 +4160,37 @@ int btf_struct_access(struct bpf_verifier_log *log, > > > return -EINVAL; > > > } > > > > > > +bool btf_struct_ids_match(struct bpf_verifier_log *log, > > > + int off, u32 id, u32 need_type_id) > > > +{ > > > + const struct btf_type *type; > > > + int err; > > > + > > > + /* Are we already done? */ > > > + if (need_type_id == id && off == 0) > > > + return true; > > > + > > > +again: > > > + type = btf_type_by_id(btf_vmlinux, id); > > > + if (!type) > > > + return false; > > > + err = btf_struct_walk(log, type, off, 1, &id); > > > > nit: this size=1 looks a bit artificial, seems like btf_struct_walk() > > will work with size==0 just as well, no? > > right, it will work the same for 0 ... not sure why I put > originaly 1 byte for size.. probably got mixed up by some > condition in btf_struct_walk that I thought 0 wouldn't pass, > but it should work, I'll change it, it's less tricky ok, I found why it's 1 ;-) it's this condition in btf_struct_walk: for_each_member(i, t, member) { /* offset of the field in bytes */ moff = btf_member_bit_offset(t, member) / 8; if (off + size <= moff) /* won't find anything, field is already too far */ break; I originaly chose to use 'size = 1' not to medle with this (and probably causing other issues) and in any case we expect that anything we find have at least byte size, so it has some logic ;-) we could make 0 size a special case and don't break the loop for it, but I wonder there's already someone calling it with zero and is expecting it to fail jirka