Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2089391rwi; Thu, 3 Nov 2022 12:30:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6hmKaGMDzLrC06fFctuQJaeFXbd22HPwg0B9DRS+lqKsoLXDtCdXaxTA7rnTANSOHswf48 X-Received: by 2002:a17:90b:3696:b0:214:1611:a497 with SMTP id mj22-20020a17090b369600b002141611a497mr15050154pjb.78.1667503846187; Thu, 03 Nov 2022 12:30:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667503846; cv=none; d=google.com; s=arc-20160816; b=UQX8vjiLSatYwoVOYTRe8EN2DDieIA7BFCAsdLpC0d4LozAlcIfJXuNWUmzPkmseLU oXEiKLmT/+xYDeHPIBV8x2ATKS08Fmyt6yA+HBpzFMuz0MlUlJ72WLcxRY8EV4evPTJm Ct3tNnbiCAvU2Ed287+x+W68kljrKbivS6pPgc4ocgb7uc57xEM+XLL9mpM5RdVeNMVh VlD5vpc4EHwk4XBz8aWeZiSpj08wvRdgRxWLrAQFs6trvKR8D8HqnR6h9Q97nUF8dmdz thloMjmpfPMnJurWNS65qFB1gFFFWYkJC9tZ97J3aAv81yRxEPm1DO5Kjt4nyOXCgWDV gAOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AdV60lwYNZHd1nY0aYC1vThK2Pv8MfHSq31cC6uqLnw=; b=QKAtsOrq0DPI4+AmPW1hJuMAeEZaB8yzANe59yMJgADSLjkjwioQszDXgl8aJNjYWO Nss0Lap61PeHOJeWWBTb/cjuTPGvvwJX99nLeK2LyfaJ78l6QSyL3zK2hdTmXA0CFD37 CGZrw+4PRxpgAlu4UTAeYI0rIuwXoaZytEmCXma93+sjQnX8vmsgwHUcDW+0uKgC16tc AlzfJsONBpt3h3GD2KmP3Z9jARwOu024Eg+Ui/V4hpKiAtSkE8meN+ETaHws209apQfc oBvjv7b1FF29WczWVGMFKfHzwlgoawf8mHuapXUQfAjhQFDxlQKPJ1mtKaOAKx9gVU5O ytAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K6vifuN+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x6-20020a056a00188600b00547a857b7b3si2189098pfh.375.2022.11.03.12.30.33; Thu, 03 Nov 2022 12:30:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K6vifuN+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229672AbiKCSiS (ORCPT + 97 others); Thu, 3 Nov 2022 14:38:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiKCSiQ (ORCPT ); Thu, 3 Nov 2022 14:38:16 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9E17F61; Thu, 3 Nov 2022 11:38:15 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id y14so7652583ejd.9; Thu, 03 Nov 2022 11:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=AdV60lwYNZHd1nY0aYC1vThK2Pv8MfHSq31cC6uqLnw=; b=K6vifuN+hyYqYGS7hup35yInLj34OLtWGhie3fL1HWrzRYZ4Pyw9WrQv+zwR9xaNvt EQ/QV8Tu02cnUS7kOoYiJ8+Psk5gXl8Sk64sAhIx+GY/zybTEVo/IRR/81CloH0b9wE1 OLzqDx4+HvQZISclU1rYRlrM78nXlORNZmXv8+eEQ7kilblLpBXkwMKtlGEnYkSup7t5 piWM6x7cY2cZxmZpLSZ+X6frGzhVWImwhujiiilkigtUmqvamsO9oBOY3IDOKOCtdtln mqi7dqAbTEfQrhRueb4ulqrYAcEt1QI9CeR6Lnx/cfIqbPS46tLdxRk2A/IrdfjYIwM+ DkuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AdV60lwYNZHd1nY0aYC1vThK2Pv8MfHSq31cC6uqLnw=; b=uo17gIli8GldREKM/FwNOMOakvPMYMZPuMjDokjeyqe+yuY3eMM27NNJ2lBajRweSi SQ+zxpKJV7/Mx2iYn+lCWYEO+Vbm8beM3xa8L5k3kqhtEkPSFeOdp69MrRi/94+3+2Xi g7WBcN5QpeeDqMX8e8FrXd1n92enk6xyxageWMF0d9+v/O0f+fTOATuWqUiTHM3ejzvh mCw/AWjhZYas0d7z8A2flC8Vg/a3Tm+ec7DfZNPZ/aHVTZV2Afz1hisHq5iU4r7at49R PEgqDW/F99BbICQsLpHTWhhwJV1RbSd0Mk/kat4DKSq4lggZuSf8xG25H4TXXOZ/bdfW e6LA== X-Gm-Message-State: ACrzQf2W2LSMexcokwdJBTyl7FdzE0WjiLeFDJxpu2PElrtMTQyhFqjX eO+ET9bbJiDl+OQUXCwmpSG+kBS+vbCFlGqx2mM= X-Received: by 2002:a17:907:7214:b0:7ad:94cf:4a36 with SMTP id dr20-20020a170907721400b007ad94cf4a36mr30312331ejc.226.1667500694357; Thu, 03 Nov 2022 11:38:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrii Nakryiko Date: Thu, 3 Nov 2022 11:38:02 -0700 Message-ID: Subject: Re: [PATCH bpf-next] samples/bpf: Fix sockex3: missing BPF prog type To: Rong Tao Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, martin.lau@linux.dev, rongtao@cestc.cn, sdf@google.com, song@kernel.org, yhs@fb.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 29, 2022 at 12:53 AM Rong Tao wrote: > > From: Rong Tao > > since commit 450b167fb9be("libbpf: clean up SEC() handling"), > sec_def_matches() does not recognize "socket/xxx" as "socket", therefore, > the BPF program type is not recognized, set "socket/xxx" to SOCKET_FILTER > solves this error. > > $ cd samples/bpf > $ sudo ./sockex3 > libbpf: prog 'bpf_func_PARSE_IP': missing BPF prog type, check ELF section name 'socket/3' > libbpf: prog 'bpf_func_PARSE_IP': failed to load: -22 > libbpf: failed to load object './sockex3_kern.o' > ERROR: loading BPF object file failed > > Signed-off-by: Rong Tao > --- You need to do changes like this: diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c index b363503357e5..db6a93e7ec53 100644 --- a/samples/bpf/sockex3_kern.c +++ b/samples/bpf/sockex3_kern.c @@ -17,7 +17,7 @@ #define IP_MF 0x2000 #define IP_OFFSET 0x1FFF -#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F +#define PROG(F) SEC("socket_filter") int bpf_func_##F struct { __uint(type, BPF_MAP_TYPE_PROG_ARRAY); @@ -279,7 +279,7 @@ PROG(PARSE_MPLS)(struct __sk_buff *skb) return 0; } -SEC("socket/0") +SEC("socket_filter") int main_prog(struct __sk_buff *skb) { __u32 nhoff = ETH_HLEN; Why fixing up after the fact at runtime, if you can just make those BPF programs conform to libbpf rules? > samples/bpf/sockex3_user.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c > index cd6fa79df900..dc79c17ad195 100644 > --- a/samples/bpf/sockex3_user.c > +++ b/samples/bpf/sockex3_user.c > @@ -39,6 +39,9 @@ int main(int argc, char **argv) > return 0; > } > > + bpf_object__for_each_program(prog, obj) > + bpf_program__set_type(prog, BPF_PROG_TYPE_SOCKET_FILTER); > + > /* load BPF program */ > if (bpf_object__load(obj)) { > fprintf(stderr, "ERROR: loading BPF object file failed\n"); > -- > 2.31.1 >