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=-3.9 required=3.0 tests=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 857AFC43603 for ; Wed, 4 Dec 2019 18:52:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55D6520661 for ; Wed, 4 Dec 2019 18:52:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BuQ/wgQm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728339AbfLDSw0 (ORCPT ); Wed, 4 Dec 2019 13:52:26 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:33985 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728154AbfLDSw0 (ORCPT ); Wed, 4 Dec 2019 13:52:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575485544; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=peb0ht/ZBvZYAPrLQwA8OcTuHG3fm58ggHVLgcRexWk=; b=BuQ/wgQm1DvbPIjbLMbW6e7QW2hweIuGch0U4HZRtDk1uHUEr2Zhw2EM/ZOLsfIew7gvHm th/DPmVdIUnurJgVNBm1KeXX/w/5Jd6KvOzzjEhJ1JTxQUw4B7V04GxBwvd/kitBb+3q9G 0EQ3QmoVj5hcfQB7vKWo1kinhP73u1s= 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-159-7vCNvlsXP_KTHPVdSj1m9Q-1; Wed, 04 Dec 2019 13:52:21 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E872D10050ED; Wed, 4 Dec 2019 18:52:19 +0000 (UTC) Received: from [10.36.118.152] (unknown [10.36.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 270355D9C5; Wed, 4 Dec 2019 18:52:18 +0000 (UTC) From: "Eelco Chaudron" To: "Yonghong Song" Cc: "Alexei Starovoitov" , Xdp , bpf Subject: Re: Trying the bpf trace a bpf xdp program Date: Wed, 04 Dec 2019 19:52:17 +0100 Message-ID: In-Reply-To: References: <3AC9D2B7-9D2F-4286-80A2-1721B51B62CF@redhat.com> <4BBF99E4-9554-44F7-8505-D4B8416554C4@redhat.com> <056E9F5E-4FDD-4636-A43A-EC98A06E84D3@redhat.com> <7062345a-1060-89f6-0c02-eef2fe0d835a@fb.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: 7vCNvlsXP_KTHPVdSj1m9Q-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 4 Dec 2019, at 19:01, Yonghong Song wrote: >>> I=E2=80=99ve put my code on GitHub, maybe it=E2=80=99s just something s= tupid=E2=80=A6 > > Thanks for the test case. This indeed a kernel bug. > The following change fixed the issue: > > > -bash-4.4$ git diff > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index a0482e1c4a77..034ef81f935b 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -9636,7 +9636,10 @@ static int check_attach_btf_id(struct > bpf_verifier_env *env) > ret =3D -EINVAL; > goto out; > } > - addr =3D (long) > tgt_prog->aux->func[subprog]->bpf_func; > + if (subprog =3D=3D 0) > + addr =3D (long) tgt_prog->bpf_func; > + else > + addr =3D (long) > tgt_prog->aux->func[subprog]->bpf_func; > } else { > addr =3D kallsyms_lookup_name(tname); > if (!addr) { > -bash-4.4$ > > The reason is for a bpf program without any additional subprogram > (callees), tgt_prog->aux->func is not populated and is a NULL pointer, > so the access tgt_prog->aux->func[0]->bpf_func will segfault. > > With the above change, your test works properly. Thanks for the quick response, and as you mention the test passes with=20 the patch above. I will continue my experiments later this week, and let you know if I=20 run into any other problems. Cheers, Eelco