From patchwork Tue Aug 25 19:21:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 261948 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=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS 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 3240BC433E1 for ; Tue, 25 Aug 2020 19:22:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13C162071E for ; Tue, 25 Aug 2020 19:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598383331; bh=b+ayeidIXbgyAiOMn2eKpg6hiyDxc603nbWdjxJmEhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NOlOUfR/SwcDgsIhqA4JIDo+wVqllD1uWiHZlj84bG8DjvEJHJtJNfAJDozj4sJ+o 8GWq5GUrmzG82I5wI6aaH/QQiPML+PAhJxSRbaI+BFHrvVn2nyCtGxV2XvoBkzE1uL fKW5pqx647J/ycFJIOJmIir8b68Y5ZAdZCou9Qp8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726946AbgHYTWJ convert rfc822-to-8bit (ORCPT ); Tue, 25 Aug 2020 15:22:09 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:58809 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726938AbgHYTWH (ORCPT ); Tue, 25 Aug 2020 15:22:07 -0400 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-566-MSdIkeLfPbyo9gV-5nzICw-1; Tue, 25 Aug 2020 15:22:00 -0400 X-MC-Unique: MSdIkeLfPbyo9gV-5nzICw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A7F66801AB7; Tue, 25 Aug 2020 19:21:58 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6E3D19C4F; Tue, 25 Aug 2020 19:21:55 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: Andrii Nakryiko , netdev@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer Subject: [PATCH v12 bpf-next 06/14] bpf: Remove recursion call in btf_struct_access Date: Tue, 25 Aug 2020 21:21:16 +0200 Message-Id: <20200825192124.710397-7-jolsa@kernel.org> In-Reply-To: <20200825192124.710397-1-jolsa@kernel.org> References: <20200825192124.710397-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: kernel.org Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Andrii suggested we can simply jump to again label instead of making recursion call. Suggested-by: Andrii Nakryiko Acked-by: Andrii Nakryiko Signed-off-by: Jiri Olsa --- kernel/bpf/btf.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index ee0e2a5e6c88..4488c5b03941 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -3931,14 +3931,13 @@ int btf_struct_access(struct bpf_verifier_log *log, /* Only allow structure for now, can be relaxed for * other types later. */ - elem_type = btf_type_skip_modifiers(btf_vmlinux, - array_elem->type, NULL); - if (!btf_type_is_struct(elem_type)) + t = btf_type_skip_modifiers(btf_vmlinux, array_elem->type, + NULL); + if (!btf_type_is_struct(t)) goto error; - off = (off - moff) % elem_type->size; - return btf_struct_access(log, elem_type, off, size, atype, - next_btf_id); + off = (off - moff) % t->size; + goto again; error: bpf_log(log, "access beyond struct %s at off %u size %u\n",